Skip to content

Commit 6227c94

Browse files
authored
chore(aws-cdk-lib): increase jest test speed, remove warnings (#26854)
Two changes to the `jest` tests: - We are currently running the tests directly from `.ts` source files using `ts-jest`. Disable type checking (by setting `isolatedModules: true`) to improve the speed. This brings down running 4 test suites from an arbitrary service (`aws-servicecatalog`) down from `79s` to `19s` on my machine. - Change the "coverage ignore files" a little to get rid of the "Note: The code generator has deoptimised the styling" errors produced by jest when it wants to read the coverage of the generated source files. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 356f302 commit 6227c94

File tree

37 files changed

+203
-160
lines changed

37 files changed

+203
-160
lines changed

Diff for: nx.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"!{workspaceRoot}/**/tsconfig.json",
1212
"!{workspaceRoot}/**/tsconfig.json",
1313
"!{workspaceRoot}/tsconfig.base.json",
14-
"!{workspaceRoot}/**/tsconfig.tsbuildinfo"
14+
"!{workspaceRoot}/**/tsconfig.tsbuildinfo",
15+
"!{workspaceRoot}/**/jest.config.js"
1516
],
1617
"outputs": [
1718
"{projectRoot}/**/*.integ.*.js.snapshot/*",

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"jsii-pacmak": "1.87.0",
2929
"jsii-reflect": "1.87.0",
3030
"jsii-rosetta": "~5.1.10",
31+
"ts-jest": "^29.1.1",
3132
"lerna": "^7.1.5",
3233
"nx": "^16.7.3",
3334
"patch-package": "^6.5.1",

Diff for: packages/@aws-cdk-testing/cli-integ/test/resource-pool.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { sleep } from '../lib';
22
import { ResourcePool } from '../lib/resource-pool';
33

4+
jest.setTimeout(30_000);
5+
46
const POOL_NAME = 'resource-pool.test';
57

68
test('take and dispose', async () => {

Diff for: packages/@aws-cdk-testing/framework-integ/.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ nyc.config.js
1414

1515
!**/*.snapshot/**/asset.*/**
1616

17-
**/*.ts.snapshot
17+
**/*.ts.snapshot
18+
19+
!jest.config.js
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
// Purposely only run .js files, not .ts files. This is so that the unit tests
4+
// here will use the jsii-compiled version of `aws-cdk-lib`, and not the live-interpreted
5+
// .ts files.
6+
moduleFileExtensions: [
7+
'js',
8+
],
9+
testMatch: [
10+
'<rootDir>/test/**/?(*.)+(test).js',
11+
],
12+
13+
testEnvironment: 'node',
14+
};

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.condition-with-ref.js.snapshot/asset.1e14e895fcbdf65feb0a29e4aa74c6c92a6fb0e41f228bef7ab23627ed409cde/consts.js

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.condition-with-ref.js.snapshot/asset.1e14e895fcbdf65feb0a29e4aa74c6c92a6fb0e41f228bef7ab23627ed409cde/index.js

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.condition-with-ref.js.snapshot/asset.a913a2614f4e118cb83fa3c0dd17575c9adbbdbad4da17aecd505282a25513f8/consts.js

-3
This file was deleted.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.condition-with-ref.js.snapshot/asset.a913a2614f4e118cb83fa3c0dd17575c9adbbdbad4da17aecd505282a25513f8/index.js

-32
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"32.0.0"}
1+
{"version":"33.0.0"}

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.condition-with-ref.js.snapshot/iamtestconditionwithrefDefaultTestDeployAssert5E44A64B.assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "32.0.0",
2+
"version": "33.0.0",
33
"files": {
44
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
55
"source": {

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.condition-with-ref.js.snapshot/integ.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2-
"version": "32.0.0",
2+
"version": "33.0.0",
33
"testCases": {
44
"iam-test-condition-with-ref/DefaultTest": {
55
"stacks": [
66
"test-condition-with-ref"
77
],
8+
"diffAssets": true,
89
"assertionStack": "iam-test-condition-with-ref/DefaultTest/DeployAssert",
910
"assertionStackName": "iamtestconditionwithrefDefaultTestDeployAssert5E44A64B"
1011
}

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.condition-with-ref.js.snapshot/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "32.0.0",
2+
"version": "33.0.0",
33
"artifacts": {
44
"test-condition-with-ref.assets": {
55
"type": "cdk:asset-manifest",
@@ -17,7 +17,7 @@
1717
"validateOnSynth": false,
1818
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
1919
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
20-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5d543b44583359346e7d4e1d73209c742ec533540ce929f2f2493fb27b0e738d.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c78c907e2231879b958741f82c29330bcd35d5778c279f9e497f7e8565e6e2cc.json",
2121
"requiresBootstrapStackVersion": 6,
2222
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2323
"additionalDependencies": [

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.condition-with-ref.js.snapshot/test-condition-with-ref.assets.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
2-
"version": "32.0.0",
2+
"version": "33.0.0",
33
"files": {
4-
"a913a2614f4e118cb83fa3c0dd17575c9adbbdbad4da17aecd505282a25513f8": {
4+
"1e14e895fcbdf65feb0a29e4aa74c6c92a6fb0e41f228bef7ab23627ed409cde": {
55
"source": {
6-
"path": "asset.a913a2614f4e118cb83fa3c0dd17575c9adbbdbad4da17aecd505282a25513f8",
6+
"path": "asset.1e14e895fcbdf65feb0a29e4aa74c6c92a6fb0e41f228bef7ab23627ed409cde",
77
"packaging": "zip"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "a913a2614f4e118cb83fa3c0dd17575c9adbbdbad4da17aecd505282a25513f8.zip",
12+
"objectKey": "1e14e895fcbdf65feb0a29e4aa74c6c92a6fb0e41f228bef7ab23627ed409cde.zip",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}
1616
},
17-
"5d543b44583359346e7d4e1d73209c742ec533540ce929f2f2493fb27b0e738d": {
17+
"c78c907e2231879b958741f82c29330bcd35d5778c279f9e497f7e8565e6e2cc": {
1818
"source": {
1919
"path": "test-condition-with-ref.template.json",
2020
"packaging": "file"
2121
},
2222
"destinations": {
2323
"current_account-current_region": {
2424
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
25-
"objectKey": "5d543b44583359346e7d4e1d73209c742ec533540ce929f2f2493fb27b0e738d.json",
25+
"objectKey": "c78c907e2231879b958741f82c29330bcd35d5778c279f9e497f7e8565e6e2cc.json",
2626
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
2727
}
2828
}

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.condition-with-ref.js.snapshot/test-condition-with-ref.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"S3Bucket": {
6666
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
6767
},
68-
"S3Key": "a913a2614f4e118cb83fa3c0dd17575c9adbbdbad4da17aecd505282a25513f8.zip"
68+
"S3Key": "1e14e895fcbdf65feb0a29e4aa74c6c92a6fb0e41f228bef7ab23627ed409cde.zip"
6969
},
7070
"Timeout": 900,
7171
"MemorySize": 128,

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.condition-with-ref.js.snapshot/tree.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
"path": "iam-test-condition-with-ref/DefaultTest/Default",
180180
"constructInfo": {
181181
"fqn": "constructs.Construct",
182-
"version": "10.2.55"
182+
"version": "10.2.69"
183183
}
184184
},
185185
"DeployAssert": {
@@ -225,7 +225,7 @@
225225
"path": "Tree",
226226
"constructInfo": {
227227
"fqn": "constructs.Construct",
228-
"version": "10.2.55"
228+
"version": "10.2.69"
229229
}
230230
}
231231
},

Diff for: packages/aws-cdk-lib/core/test/runtime-info.test.ts renamed to packages/@aws-cdk-testing/framework-integ/test/core/test/runtime-info.test.ts

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,26 @@
1+
/**
2+
* Unit tests that depend on 'aws-cdk-lib' having been compiled using jsii
3+
*/
14
import * as fs from 'fs';
25
import * as path from 'path';
36
import { Construct } from 'constructs';
4-
import { App, NestedStack, Stack, Stage, IPolicyValidationPluginBeta1, PolicyViolationBeta1, PolicyValidationPluginReportBeta1, IPolicyValidationContextBeta1 } from '../lib';
5-
import { constructInfoFromConstruct, constructInfoFromStack } from '../lib/private/runtime-info';
7+
import { App, NestedStack, Stack, Stage, IPolicyValidationPluginBeta1, PolicyViolationBeta1, PolicyValidationPluginReportBeta1, IPolicyValidationContextBeta1 } from 'aws-cdk-lib';
8+
import { constructInfoFromConstruct, constructInfoFromStack } from 'aws-cdk-lib/core/lib/helpers-internal';
69

710
const JSII_RUNTIME_SYMBOL = Symbol.for('jsii.rtti');
811

912
let app: App;
1013
let stack: Stack;
1114
let _cdkVersion: string | undefined = undefined;
1215

13-
// The runtime metadata this test relies on is only available if the most
14-
// recent compile has happened using 'jsii', as the jsii compiler injects
15-
// this metadata.
16-
//
17-
// If the most recent compile was using 'tsc', the metadata will not have
18-
// been injected, and the test suite will fail.
19-
//
20-
// Tolerate `tsc` builds locally, but not on CodeBuild.
21-
const codeBuild = !!process.env.CODEBUILD_BUILD_ID;
22-
const moduleCompiledWithTsc = constructInfoFromConstruct(new Stack())?.fqn === 'constructs.Construct';
23-
let describeTscSafe = describe;
24-
if (moduleCompiledWithTsc && !codeBuild) {
25-
// eslint-disable-next-line
26-
console.error('It appears this module was compiled with `tsc` instead of `jsii` in a local build. Skipping this test suite.');
27-
describeTscSafe = describe.skip;
28-
}
29-
3016
beforeEach(() => {
3117
app = new App();
3218
stack = new Stack(app, 'Stack', {
3319
analyticsReporting: true,
3420
});
3521
});
3622

37-
describeTscSafe('constructInfoFromConstruct', () => {
23+
describe('constructInfoFromConstruct', () => {
3824
test('returns fqn and version for core constructs', () => {
3925
const constructInfo = constructInfoFromConstruct(stack);
4026
expect(constructInfo).toBeDefined();
@@ -70,7 +56,7 @@ describeTscSafe('constructInfoFromConstruct', () => {
7056
});
7157
});
7258

73-
describeTscSafe('constructInfoForStack', () => {
59+
describe('constructInfoForStack', () => {
7460
test('returns stack itself and jsii runtime if stack is empty', () => {
7561
const constructInfos = constructInfoFromStack(stack);
7662

Diff for: packages/aws-cdk-lib/core/test/private/tree-metadata.test.ts renamed to packages/@aws-cdk-testing/framework-integ/test/core/test/tree-metadata.test.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
/**
2+
* Unit tests that depend on 'aws-cdk-lib' having been compiled using jsii
3+
*/
14
import * as fs from 'fs';
25
import * as path from 'path';
36
import { Construct } from 'constructs';
4-
import * as cxschema from '../../../cloud-assembly-schema';
5-
import { App, CfnParameter, CfnResource, Lazy, Stack, TreeInspector } from '../../lib/index';
7+
import * as cxschema from 'aws-cdk-lib/cloud-assembly-schema';
8+
import { App, CfnParameter, CfnResource, Lazy, Stack, TreeInspector } from 'aws-cdk-lib';
69

710
abstract class AbstractCfnResource extends CfnResource {
811
constructor(scope: Construct, id: string) {
@@ -160,21 +163,19 @@ describe('tree metadata', () => {
160163
const treeArtifact = assembly.tree();
161164
expect(treeArtifact).toBeDefined();
162165

163-
const codeBuild = !!process.env.CODEBUILD_BUILD_ID;
164-
165166
expect(readJson(assembly.directory, treeArtifact!.file)).toEqual({
166167
version: 'tree-0.1',
167168
tree: expect.objectContaining({
168169
children: expect.objectContaining({
169170
mystack: expect.objectContaining({
170171
constructInfo: {
171-
fqn: expect.stringMatching(codeBuild ? /\bStack$/ : /\bStack$|^constructs.Construct$/),
172+
fqn: expect.stringMatching(/\bStack$/),
172173
version: expect.any(String),
173174
},
174175
children: expect.objectContaining({
175176
myconstruct: expect.objectContaining({
176177
constructInfo: {
177-
fqn: expect.stringMatching(codeBuild ? /\bCfnResource$/ : /\bCfnResource$|^constructs.Construct$/),
178+
fqn: expect.stringMatching(/\bCfnResource$/),
178179
version: expect.any(String),
179180
},
180181
}),
@@ -398,4 +399,4 @@ describe('tree metadata', () => {
398399

399400
function readJson(outdir: string, file: string) {
400401
return JSON.parse(fs.readFileSync(path.join(outdir, file), 'utf-8'));
401-
}
402+
}

Diff for: packages/@aws-cdk/app-staging-synthesizer-alpha/test/app-staging-synthesizer.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe(AppStagingSynthesizer, () => {
137137

138138
// THEN - we have a fixed asset location
139139
expect(evalCFN(location.bucketName)).toEqual(`cdk-${APP_ID}-staging-000000000000-us-east-1`);
140-
expect(evalCFN(location.httpUrl)).toEqual(`https://s3.us-east-1.domain.aws/cdk-${APP_ID}-staging-000000000000-us-east-1/abcdef.js`);
140+
expect(evalCFN(location.httpUrl)).toEqual(`https://s3.us-east-1.domain.aws/cdk-${APP_ID}-staging-000000000000-us-east-1/abcdef.ts`);
141141

142142
// THEN - object key contains source hash somewhere
143143
expect(location.objectKey.indexOf('abcdef')).toBeGreaterThan(-1);
@@ -187,7 +187,7 @@ describe(AppStagingSynthesizer, () => {
187187
});
188188

189189
// THEN - asset has deploy time prefix
190-
expect(evalCFN(location.objectKey)).toEqual(`${DEPLOY_TIME_PREFIX}abcdef.js`);
190+
expect(evalCFN(location.objectKey)).toEqual(`${DEPLOY_TIME_PREFIX}abcdef.ts`);
191191
});
192192

193193
test('lambda assets are by default deploy time assets', () => {

Diff for: packages/@aws-cdk/cloud-assembly-schema/jest.config.js

-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
const baseConfig = require('@aws-cdk/cdk-build-tools/config/jest.config');
22
module.exports = {
33
...baseConfig,
4-
moduleFileExtensions: [
5-
'js',
6-
'ts',
7-
],
8-
preset: 'ts-jest',
94
testMatch: [
105
'<rootDir>/**/test/**/?(*.)+(test).ts',
116
],

Diff for: packages/@aws-cdk/cx-api/jest.config.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
const baseConfig = require('@aws-cdk/cdk-build-tools/config/jest.config');
22
module.exports = {
3-
...baseConfig,
4-
moduleFileExtensions: [
5-
'js',
6-
'ts',
7-
],
8-
preset: 'ts-jest',
9-
testMatch: [
10-
'<rootDir>/**/test/**/?(*.)+(test).ts',
11-
],
3+
...baseConfig,
124
coverageThreshold: {
135
global: {
146
...baseConfig.coverageThreshold.global,

0 commit comments

Comments
 (0)