Aws-cdk: Assert failed after update assert module

Created on 30 Oct 2019  路  7Comments  路  Source: aws/aws-cdk

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?

Reproduction Steps

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)
```

Environment

  • CLI Version : 1.15.0
  • Framework Version: 1.15.0
  • OS : macOS
  • Language : Node.js 12.13.0

Other


This is :bug: Bug Report

@aws-cdassert bug response-requested

Most helpful comment

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!

All 7 comments

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

  • Confirmed cdk/* packages have the same version 1.27.0
  • Removed node_modules, reinstalled all packages
  • Ran a new build

While 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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abelmokadem picture abelmokadem  路  3Comments

ababra picture ababra  路  3Comments

artyom-melnikov picture artyom-melnikov  路  3Comments

NukaCody picture NukaCody  路  3Comments

Kent1 picture Kent1  路  3Comments