Skip to content

Commit 8a14b0b

Browse files
author
Michael Kaiser
committed
Fix snapshot tests by normalizing asset hashes
1 parent c9e4448 commit 8a14b0b

File tree

7 files changed

+41
-37
lines changed

7 files changed

+41
-37
lines changed

typescript/api-gateway-lambda-token-authorizer/test/stack/gateway-lambda-auth-stack.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ describe('Snapshot', () => {
99
const app = new App();
1010
const stack = new GatewayLambdaAuth(app, 'test-api-gateway-lambda-auth');
1111
const template = Template.fromStack(stack);
12-
1312
// Normalize the template before snapshot comparison
1413
const normalizedTemplate = normalizeTemplate(template.toJSON());
1514
expect(normalizedTemplate).toMatchSnapshot();
1615
});
16+
1717
})
1818

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
roots: ['<rootDir>/test'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
}
8+
};
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { Template } from 'aws-cdk-lib/assertions';
22
import { IntegTesting } from '../src/integ.default';
3+
import { normalizeTemplate } from '../../test-utils/normalize-template';
34

45
test('default validation', () => {
56
const integ = new IntegTesting();
67
integ.stack.forEach(stack => {
78
const t = Template.fromStack(stack);
9+
// Normalize the template before snapshot comparison
10+
const normalizedTemplate = normalizeTemplate(t.toJSON());
811
// should match snapshot
9-
expect(t).toMatchSnapshot();
12+
expect(normalizedTemplate).toMatchSnapshot();
1013
});
1114
});
Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
{
22
"compilerOptions": {
3-
"outDir": "lib",
4-
"rootDir": "src",
5-
"declarationMap": false,
6-
"inlineSourceMap": true,
7-
"inlineSources": true,
8-
"alwaysStrict": true,
3+
"target": "ES2018",
4+
"module": "commonjs",
5+
"lib": ["es2018"],
96
"declaration": true,
10-
"experimentalDecorators": true,
11-
"incremental": true,
12-
"lib": [
13-
"es2020"
14-
],
15-
"module": "CommonJS",
16-
"noEmitOnError": true,
17-
"noFallthroughCasesInSwitch": true,
18-
"noImplicitAny": true,
19-
"noImplicitReturns": true,
20-
"noImplicitThis": true,
21-
"noUnusedLocals": true,
22-
"noUnusedParameters": true,
23-
"resolveJsonModule": true,
24-
"skipLibCheck": true,
257
"strict": true,
8+
"noImplicitAny": true,
269
"strictNullChecks": true,
27-
"strictPropertyInitialization": true,
28-
"stripInternal": false,
29-
"target": "ES2020",
30-
"composite": false,
31-
"tsBuildInfoFile": "lib/tsconfig.tsbuildinfo"
10+
"noImplicitThis": true,
11+
"alwaysStrict": true,
12+
"noUnusedLocals": false,
13+
"noUnusedParameters": false,
14+
"noImplicitReturns": true,
15+
"noFallthroughCasesInSwitch": false,
16+
"inlineSourceMap": true,
17+
"inlineSources": true,
18+
"experimentalDecorators": true,
19+
"strictPropertyInitialization": false,
20+
"typeRoots": ["./node_modules/@types"],
21+
"outDir": "dist"
3222
},
33-
"include": [
34-
"src/**/*.ts"
35-
],
36-
"exclude": [
37-
"node_modules"
38-
]
23+
"exclude": ["node_modules", "cdk.out"]
3924
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
roots: ['<rootDir>/test'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
}
8+
};

typescript/ec2-instance/test/main.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { App, Stack } from 'aws-cdk-lib';
22
import { Template } from 'aws-cdk-lib/assertions';
33
import { EC2Example } from '../src/ec2-instance';
44
import { InstanceSize, CPUTypes } from '../src/envValidator';
5+
import { normalizeTemplate } from '../../test-utils/normalize-template';
56

67
const devEnv = {
78
account: process.env.CDK_DEFAULT_ACCOUNT,
@@ -28,7 +29,8 @@ test('Snapshot', () => {
2829
});
2930

3031
const template = Template.fromStack(stack);
31-
expect(template.toJSON()).toMatchSnapshot();
32+
const normalizedTemplate = normalizeTemplate(template.toJSON());
33+
expect(normalizedTemplate).toMatchSnapshot();
3234
});
3335

3436
test('LARGE', () => {

typescript/inspector2/test/__snapshots__/inspector2-monitoring-resource.test.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ exports[`Inspector2MonitoringResource creates required resources 1`] = `
145145
},
146146
"S3Key": "NORMALIZED_ASSET_HASH.zip",
147147
},
148-
},
149148
"Handler": "index.handler",
150149
"Role": {
151150
"Fn::GetAtt": [
@@ -223,7 +222,6 @@ exports[`Inspector2MonitoringResource creates required resources 1`] = `
223222
},
224223
"S3Key": "NORMALIZED_ASSET_HASH.zip",
225224
},
226-
},
227225
"Handler": "index.handler",
228226
"Role": {
229227
"Fn::GetAtt": [

0 commit comments

Comments
 (0)