jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.28k stars 6.47k forks source link

[Bug]: Snapshot Test Fails After Setting Multiple CloudWatch Alarms to the Same Lambda (AWS CDK v2.136.0 or Later) #15376

Open mickey-DWS opened 5 days ago

mickey-DWS commented 5 days ago

Version

29.7.0

Steps to reproduce

  1. Use AWS CDK version v2.136.0 or later.
  2. Create multiple CloudWatch alarms and attach them to the same Lambda function as shown in the code snippet above.
  3. Run Jest snapshot tests for the CloudFormation stack or Lambda configuration.
  4. Observe that the snapshot test fails with the error: There is already a Construct with name 'AlarmPermission' in NodejsFunction [<LambdaFunctionName>].

Expected behavior

I expect the snapshot tests to pass when multiple CloudWatch alarms are attached to the same Lambda function, as AWS CDK v2.136.0 or later now allows this configuration without errors during deployment.

Image

Actual behavior

The snapshot tests fail with the following error message:

There is already a Construct with name 'AlarmPermission' in NodejsFunction [EmailContentFormatter]

Additional context

Even though the deployment works correctly and the Lambda function is successfully attached to multiple CloudWatch alarms, Jest's snapshot mechanism does not seem to handle this updated behavior properly.

Environment

System:
  OS: macOS 15.0.1
  CPU: (8) arm64 Apple M2
Binaries:
  Node: 18.18.2 - ~/.volta/tools/image/node/18.18.2/bin/node
  Yarn: 4.2.2 - ~/.volta/tools/image/yarn/4.2.2/bin/yarn
  npm: 9.8.1 - ~/.volta/tools/image/node/18.18.2/bin/npm
  pnpm: 8.10.0 - ~/.volta/bin/pnpm
npmPackages:
  jest: ^29.7.0 => 29.7.0