-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(assertions): Can't do snapshot testing of Stacks using the same App #18847
Comments
The reason why I use the same App all the time is that in the actual production code, I create a stack of ECR repositories and reference the fields to the stack of ECS repositories. |
@ncaq did you ever figure this out? I've run into the same issue. |
@amirmishani |
Try creating both stacks first, and only after that create the Template objects and assertions. Somehow fixed things for me, still no idea why 🤷 |
When
aws-cdk/packages/@aws-cdk/core/lib/stage.ts Lines 181 to 190 in bd056d1
So when you reuse the The answer to this is:
|
So in the current example, I suggest doing something like (comments optional): import { App, Stack } from "aws-cdk-lib";
import { Template } from "aws-cdk-lib/assertions";
test("snapshot foo", () => {
// arrange
const app = new App();
// act
const fooStack = new Stack(app, "FooStack");
const fooTemplate = Template.fromStack(fooStack);
// assert
expect(fooTemplate.toJSON()).toMatchSnapshot("FooStack");
});
test("snapshot bar", () => {
const app = new App();
const barStack = new Stack(app, "BarStack");
const barTemplate = Template.fromStack(barStack);
expect(barTemplate.toJSON()).toMatchSnapshot("BarStack");
}); |
What is the problem?
I migrate AWS CDK v1 to v2.
And I use assertion from assert because assert is deprecated.
My project have snapshot test.
When I rewrote this into assertions, I received an error that was difficult to resolve.
I thought that the complicated configuration I had done so far was bad, but it was reproduced when I created a new AWS CDK project and wrote test code.
Reproduction Steps
paste.
npm run test
What did you expect to happen?
This is a snapshot test, so we expect it to succeed unconditionally the first time.
What actually happened?
CDK CLI Version
2.10.0 (build e5b301f)
Framework Version
No response
Node.js Version
v16.13.1
OS
Linux strawberry 5.15.19-gentoo #1 SMP Sat Feb 5 10:10:29 JST 2022 x86_64 AMD Ryzen Threadripper 1950X 16-Core Processor AuthenticAMD GNU/Linux
Language
Typescript
Language Version
3.9.7
Other information
relation?
The text was updated successfully, but these errors were encountered: