I used Jest with AWS CDK Assert module to test against the CDK output just like example.
It was fine when I have @aws/cdk/assert 1.13.1 or the lower version installed.
But after update @aws/cdk/assert to 1.14.0 or 1.15.0, all tests always failed with:
None of 0 resources matches resource ....
If I reinstalled @aws/cdk/assert 1.13.1, the tests will pass again.
The output of cdk synth & deployment is good though.
Is there a possibility of regression from upgrading 1.13.1 to 1.14.0?
with @aws/cdk/assert 1.14.0 or 1.15.0
```javascript=
class SampleStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
new events.Rule(this, 'timer', {
description: 'Execute every 5 min',
schedule: events.Schedule.rate(cdk.Duration.minutes(5)),
});
}
}
module.exports = SampleStack;
const { expect: expectCDK, haveResource } = require('@aws-cdk/assert');
...
test('Event Created', () => {
const app = new cdk.App();
const stack = new SampleStack(app, 'testStack');
expectCDK(stack).to(haveResource('AWS::Events::Rule'));
});
### Error Log
None of 0 resources matches resource 'AWS::Events::Rule' with properties undefined.
at HaveResourceAssertion.assertOrThrow (node_modules/@aws-cdk/assert/lib/assertions/have-resource.ts:83:13)
at StackInspector._to (node_modules/@aws-cdk/assert/lib/inspector.ts:25:15)
at StackInspector.to (node_modules/@aws-cdk/assert/lib/inspector.ts:15:25)
at Object.to (test/stack.test.js:16:20)
```
1.15.01.15.0macOSNode.js 12.13.0This is :bug: Bug Report
I guess you may have been bit by having multiple different (possibly incompatible) versions of the @aws-cdk/* libraries in your closure, which can cause unexpected behavior.
Can you comment as to whether this could have been the case?
Hi @RomainMuller ,
After removing node_modules & package-lock.json, reinstalled all @aws-cdk packages with version 1.15.0, the assertion is working as expected again!
Yes, I think it is the case. somehow the upgrade procedure was messed up.
Thanks for the heads up!
Hi - First time trying to test a CDK construct/stack and facing this issue now. Let me know if you want me to create a new issue..
Test
import { expect as expectCDK, haveResource } from '@aws-cdk/assert';
import { App } from '@aws-cdk/core';
import WorkshopStack = require('../lib/workshop');
test('Snapshot test', () => {
const app = new App();
const stack = new WorkshopStack.Workshop(app, 'MyTestStack');
let editorResource = 'AWS::Cloud9::EnvironmentEC2'
expectCDK(stack).to(haveResource(editorResource))
});
I can paste the workshop code but that's rather big... essentially it creates Cloud9 environments based along with IAM Users, VPC, and a SAR App --- As I'm getting "0" resources I'm sure I'm either doing something wrong or this still exists.
Steps I've tried to resolve this
1.27.0While troubleshooting with @richardhboyd, deleting package-lock.json, node_modules, and reinstalling all packages did the trick.
馃帀
If there isn't one already, I'd be happy to create a feature request to improve error messages around package versions mismatch as I got caught by that 3 times today while experimenting with CDK
Yes, deleting package-lock.json is the key. Using npm-check to update all dependancies at once instead of update one by one seems works for me too (not sure if it makes a difference).
Had conflicting cdk versions and this did the trick
rm -rf node_modules && rm -rf package-lock.json && npm install
I'd like to re-confirm that this issue presented for me, and after deleting node_modules and package-lock.json, and then running "npm install", the issues were fixed
Most helpful comment
Hi @RomainMuller ,
After removing
node_modules&package-lock.json, reinstalled all@aws-cdkpackages with version1.15.0, the assertion is working as expected again!Yes, I think it is the case. somehow the upgrade procedure was messed up.
Thanks for the heads up!