Skip to content

gammarers/jest-aws-cdk-asset-filename-renamer

Repository files navigation

Jest aws cdk asset filename renamer

GitHub npm (scoped) GitHub Workflow Status (branch) GitHub release (latest SemVer)

this package is aws cdk construct asset filename renaming(RandomString.zip to HASH.zip)

Installation

npm install --save-dev @gammarers/jest-aws-cdk-asset-filename-renamer

Usage

You need to tell Jest to use the serializer. Add this to your Jest config:

"snapshotSerializers": [
  "<rootDir>/node_modules/@gammarers/jest-aws-cdk-asset-filename-renamer"
]

or add this projenrc.ts

  jestOptions: {
    jestConfig: {
      snapshotSerializers: ['<rootDir>/node_modules/@gammarers/jest-aws-cdk-asset-filename-renamer']
    }
  }

And your test.

const stack = new Stack(app, 'TestStack');
new lambda.Function(stack, 'Function', {
    runtime: lambda.Runtime.NODEJS_22_X,
    code: lambda.Code.fromAsset(path.join(__dirname, '../asset/sample-func')),
    handler: 'index.lambda_handler',
});
const template = Template.fromStack(stack);
expect(template.toJSON()).toMatchSnapshot();