Skip to content

Commit

Permalink
mock TrackingTag in tests
Browse files Browse the repository at this point in the history
Mocking this means we can make the value static and it doesn't need updating when new versions of the library are published.

Configuring Jest's `setupFilesAfterEnv` means we apply the mock globally. See https://jestjs.io/docs/en/configuration.html#setupfilesafterenv-array.
  • Loading branch information
akash1810 committed Feb 3, 2021
1 parent dfb64d8 commit 1bba71f
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 23 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ module.exports = {
transform: {
"^.+\\.tsx?$": "ts-jest",
},
setupFilesAfterEnv: ["./jest.setup.js"],
};
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jest.mock("./src/constants/library-info");
8 changes: 8 additions & 0 deletions src/constants/__mocks__/library-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const LibraryInfo = {
VERSION: "TEST",
};

export const TrackingTag = {
Key: "X-Gu-CDK-Version",
Value: LibraryInfo.VERSION,
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
"Timeout": 30,
Expand Down Expand Up @@ -111,7 +111,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion src/constructs/iam/policies/__snapshots__/ses.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down Expand Up @@ -410,7 +410,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down Expand Up @@ -626,7 +626,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down
24 changes: 12 additions & 12 deletions src/constructs/lambda/__snapshots__/lambda.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
"Timeout": 30,
Expand Down Expand Up @@ -165,7 +165,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down Expand Up @@ -244,7 +244,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down Expand Up @@ -432,13 +432,13 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
},
"lambdaapi2Deployment4ECB937324608a148e4c74ee74e20f580623b2d9": Object {
"lambdaapi2Deployment4ECB937340ba28821c4d87686bb600192997b7b2": Object {
"DependsOn": Array [
"lambdaapi2proxyANY3F8E1D36",
"lambdaapi2proxyE68FDFBC",
Expand All @@ -455,7 +455,7 @@ Object {
"lambdaapi2DeploymentStageprodCC9E3016": Object {
"Properties": Object {
"DeploymentId": Object {
"Ref": "lambdaapi2Deployment4ECB937324608a148e4c74ee74e20f580623b2d9",
"Ref": "lambdaapi2Deployment4ECB937340ba28821c4d87686bb600192997b7b2",
},
"RestApiId": Object {
"Ref": "lambdaapi239350ECC",
Expand All @@ -480,7 +480,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down Expand Up @@ -777,7 +777,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down Expand Up @@ -830,13 +830,13 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
},
"lambdaapiDeployment8E95B585b22be554088fbcc2c63fc037a54e995d": Object {
"lambdaapiDeployment8E95B58515e203156872c143be11756a3c89fbba": Object {
"DependsOn": Array [
"lambdaapiproxyANYA94E968A",
"lambdaapiproxyB573C729",
Expand All @@ -853,7 +853,7 @@ Object {
"lambdaapiDeploymentStageprod9598BC2F": Object {
"Properties": Object {
"DeploymentId": Object {
"Ref": "lambdaapiDeployment8E95B585b22be554088fbcc2c63fc037a54e995d",
"Ref": "lambdaapiDeployment8E95B58515e203156872c143be11756a3c89fbba",
},
"RestApiId": Object {
"Ref": "lambdaapiC1812993",
Expand All @@ -878,7 +878,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down
4 changes: 2 additions & 2 deletions src/patterns/__snapshots__/scheduled-lambda.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
"Timeout": 30,
Expand Down Expand Up @@ -162,7 +162,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down
6 changes: 3 additions & 3 deletions src/patterns/__snapshots__/sns-lambda.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down Expand Up @@ -95,7 +95,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
"Timeout": 30,
Expand Down Expand Up @@ -215,7 +215,7 @@ Object {
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
"Value": "TEST",
},
],
},
Expand Down

0 comments on commit 1bba71f

Please sign in to comment.