expect (from @aws-cdk/assert) fails when passed a CloudFormationStackArtifact #6083
Labels
@aws-cdk/assert
Related to the @aws-cdk/assert package
bug
This issue is a bug.
needs-triage
This issue or PR still needs to be triaged.
p2
The override of
expect
defined in@aws-cdk/assert
fails when passed aCloudFormationStackArtifact
object retrieved with theSynthUtils
api. This only happens in projects which do not have a flat dependency tree, instead producing the full dependency tree (which should be supported) in node_modules. The root of the problem is that@aws-cdk/core
has@aws-cdk/cx-api
as a direct dependency even though it exposes classes within@aws-cdk/cx-api
(theCloudFormationStackArtifact
retrieved thoughSynthUtils
is ultimately created inConstructNode
. This means that when theinstanceof
operator is used on aCloudFormationStackArtifact
anywhere in@aws-cdk/assert
, the left hand side was created by the@aws-cdk/cx-api
module required by@aws-cdk/core
, whereas the right hand side class comes from the@aws-cdk/cx-api
module required by@aws-cdk/assert
. This causesinstanceof
to return false.In addition to the issue with
expect
(which I think is most serious), this problem causes several other methods (likeSynthUtils.toCloudFormation
within@aws-cdk/assert
to misbehave subtly).Reproduction Steps
While I've only been able to naturally reproduce this in my own project (which I cannot share here), this is fairly easy to reproduce with the simple project created by
cdk init
. Just follow these steps:mkdir dep-test && cd dep-test
cdk init --typescript
dep-test/test/dep-test.test.ts
with the attached file.dep-test.test.txt
At this point, running
npm run test
succeeds becausenpm install
creates a flatnode_modules
. To reproduce the error, we need to simulate the results of using an older version of npm, or any other build system which creates the full dependency tree.mkdir -p node_modules/@aws-cdk/assert/node_modules/@aws-cdk && cp -r node_modules/@aws-cdk/cx-api "$_"
mkdir -p node_modules/@aws-cdk/core/node_modules/@aws-cdk && cp -r node_modules/@aws-cdk/cx-api "$_"
Now running
npm run test
fails, for the reason I described earlier in this report.Error Log
Environment
Other
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: