Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(aws-cdk-lib): increase jest test speed, remove warnings #26854

Merged
merged 21 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"!{workspaceRoot}/**/tsconfig.json",
"!{workspaceRoot}/**/tsconfig.json",
"!{workspaceRoot}/tsconfig.base.json",
"!{workspaceRoot}/**/tsconfig.tsbuildinfo"
"!{workspaceRoot}/**/tsconfig.tsbuildinfo",
"!{workspaceRoot}/**/jest.config.js"
],
"outputs": [
"{projectRoot}/**/*.integ.*.js.snapshot/*",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"jsii-pacmak": "1.87.0",
"jsii-reflect": "1.87.0",
"jsii-rosetta": "~5.1.10",
"ts-jest": "^29.1.1",
"lerna": "^7.1.5",
"nx": "^16.7.3",
"patch-package": "^6.5.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { sleep } from '../lib';
import { ResourcePool } from '../lib/resource-pool';

jest.setTimeout(30_000);

const POOL_NAME = 'resource-pool.test';

test('take and dispose', async () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk-testing/framework-integ/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ nyc.config.js

!**/*.snapshot/**/asset.*/**

**/*.ts.snapshot
**/*.ts.snapshot

!jest.config.js
14 changes: 14 additions & 0 deletions packages/@aws-cdk-testing/framework-integ/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
// Purposely only run .js files, not .ts files. This is so that the unit tests
// here will use the jsii-compiled version of `aws-cdk-lib`, and not the live-interpreted
// .ts files.
moduleFileExtensions: [
'js',
],
testMatch: [
'<rootDir>/test/**/?(*.)+(test).js',
],

testEnvironment: 'node',
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"32.0.0"}
{"version":"33.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "32.0.0",
"version": "33.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"version": "32.0.0",
"version": "33.0.0",
"testCases": {
"iam-test-condition-with-ref/DefaultTest": {
"stacks": [
"test-condition-with-ref"
],
"diffAssets": true,
"assertionStack": "iam-test-condition-with-ref/DefaultTest/DeployAssert",
"assertionStackName": "iamtestconditionwithrefDefaultTestDeployAssert5E44A64B"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "32.0.0",
"version": "33.0.0",
"artifacts": {
"test-condition-with-ref.assets": {
"type": "cdk:asset-manifest",
Expand All @@ -17,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5d543b44583359346e7d4e1d73209c742ec533540ce929f2f2493fb27b0e738d.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c78c907e2231879b958741f82c29330bcd35d5778c279f9e497f7e8565e6e2cc.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"version": "32.0.0",
"version": "33.0.0",
"files": {
"a913a2614f4e118cb83fa3c0dd17575c9adbbdbad4da17aecd505282a25513f8": {
"1e14e895fcbdf65feb0a29e4aa74c6c92a6fb0e41f228bef7ab23627ed409cde": {
"source": {
"path": "asset.a913a2614f4e118cb83fa3c0dd17575c9adbbdbad4da17aecd505282a25513f8",
"path": "asset.1e14e895fcbdf65feb0a29e4aa74c6c92a6fb0e41f228bef7ab23627ed409cde",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "a913a2614f4e118cb83fa3c0dd17575c9adbbdbad4da17aecd505282a25513f8.zip",
"objectKey": "1e14e895fcbdf65feb0a29e4aa74c6c92a6fb0e41f228bef7ab23627ed409cde.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"5d543b44583359346e7d4e1d73209c742ec533540ce929f2f2493fb27b0e738d": {
"c78c907e2231879b958741f82c29330bcd35d5778c279f9e497f7e8565e6e2cc": {
"source": {
"path": "test-condition-with-ref.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "5d543b44583359346e7d4e1d73209c742ec533540ce929f2f2493fb27b0e738d.json",
"objectKey": "c78c907e2231879b958741f82c29330bcd35d5778c279f9e497f7e8565e6e2cc.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "a913a2614f4e118cb83fa3c0dd17575c9adbbdbad4da17aecd505282a25513f8.zip"
"S3Key": "1e14e895fcbdf65feb0a29e4aa74c6c92a6fb0e41f228bef7ab23627ed409cde.zip"
},
"Timeout": 900,
"MemorySize": 128,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
"path": "iam-test-condition-with-ref/DefaultTest/Default",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.55"
"version": "10.2.69"
}
},
"DeployAssert": {
Expand Down Expand Up @@ -225,7 +225,7 @@
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.55"
"version": "10.2.69"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
/**
* Unit tests that depend on 'aws-cdk-lib' having been compiled using jsii
*/
import * as fs from 'fs';
import * as path from 'path';
import { Construct } from 'constructs';
import { App, NestedStack, Stack, Stage, IPolicyValidationPluginBeta1, PolicyViolationBeta1, PolicyValidationPluginReportBeta1, IPolicyValidationContextBeta1 } from '../lib';
import { constructInfoFromConstruct, constructInfoFromStack } from '../lib/private/runtime-info';
import { App, NestedStack, Stack, Stage, IPolicyValidationPluginBeta1, PolicyViolationBeta1, PolicyValidationPluginReportBeta1, IPolicyValidationContextBeta1 } from 'aws-cdk-lib';
import { constructInfoFromConstruct, constructInfoFromStack } from 'aws-cdk-lib/core/lib/helpers-internal';

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

let app: App;
let stack: Stack;
let _cdkVersion: string | undefined = undefined;

// The runtime metadata this test relies on is only available if the most
// recent compile has happened using 'jsii', as the jsii compiler injects
// this metadata.
//
// If the most recent compile was using 'tsc', the metadata will not have
// been injected, and the test suite will fail.
//
// Tolerate `tsc` builds locally, but not on CodeBuild.
const codeBuild = !!process.env.CODEBUILD_BUILD_ID;
const moduleCompiledWithTsc = constructInfoFromConstruct(new Stack())?.fqn === 'constructs.Construct';
let describeTscSafe = describe;
if (moduleCompiledWithTsc && !codeBuild) {
// eslint-disable-next-line
console.error('It appears this module was compiled with `tsc` instead of `jsii` in a local build. Skipping this test suite.');
describeTscSafe = describe.skip;
}

beforeEach(() => {
app = new App();
stack = new Stack(app, 'Stack', {
analyticsReporting: true,
});
});

describeTscSafe('constructInfoFromConstruct', () => {
describe('constructInfoFromConstruct', () => {
test('returns fqn and version for core constructs', () => {
const constructInfo = constructInfoFromConstruct(stack);
expect(constructInfo).toBeDefined();
Expand Down Expand Up @@ -70,7 +56,7 @@ describeTscSafe('constructInfoFromConstruct', () => {
});
});

describeTscSafe('constructInfoForStack', () => {
describe('constructInfoForStack', () => {
test('returns stack itself and jsii runtime if stack is empty', () => {
const constructInfos = constructInfoFromStack(stack);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/**
* Unit tests that depend on 'aws-cdk-lib' having been compiled using jsii
*/
import * as fs from 'fs';
import * as path from 'path';
import { Construct } from 'constructs';
import * as cxschema from '../../../cloud-assembly-schema';
import { App, CfnParameter, CfnResource, Lazy, Stack, TreeInspector } from '../../lib/index';
import * as cxschema from 'aws-cdk-lib/cloud-assembly-schema';
import { App, CfnParameter, CfnResource, Lazy, Stack, TreeInspector } from 'aws-cdk-lib';

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

const codeBuild = !!process.env.CODEBUILD_BUILD_ID;

expect(readJson(assembly.directory, treeArtifact!.file)).toEqual({
version: 'tree-0.1',
tree: expect.objectContaining({
children: expect.objectContaining({
mystack: expect.objectContaining({
constructInfo: {
fqn: expect.stringMatching(codeBuild ? /\bStack$/ : /\bStack$|^constructs.Construct$/),
fqn: expect.stringMatching(/\bStack$/),
version: expect.any(String),
},
children: expect.objectContaining({
myconstruct: expect.objectContaining({
constructInfo: {
fqn: expect.stringMatching(codeBuild ? /\bCfnResource$/ : /\bCfnResource$|^constructs.Construct$/),
fqn: expect.stringMatching(/\bCfnResource$/),
version: expect.any(String),
},
}),
Expand Down Expand Up @@ -398,4 +399,4 @@ describe('tree metadata', () => {

function readJson(outdir: string, file: string) {
return JSON.parse(fs.readFileSync(path.join(outdir, file), 'utf-8'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe(AppStagingSynthesizer, () => {

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

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

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

test('lambda assets are by default deploy time assets', () => {
Expand Down
5 changes: 0 additions & 5 deletions packages/@aws-cdk/cloud-assembly-schema/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
const baseConfig = require('@aws-cdk/cdk-build-tools/config/jest.config');
module.exports = {
...baseConfig,
moduleFileExtensions: [
'js',
'ts',
],
preset: 'ts-jest',
testMatch: [
'<rootDir>/**/test/**/?(*.)+(test).ts',
],
Expand Down
10 changes: 1 addition & 9 deletions packages/@aws-cdk/cx-api/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
const baseConfig = require('@aws-cdk/cdk-build-tools/config/jest.config');
module.exports = {
...baseConfig,
moduleFileExtensions: [
'js',
'ts',
],
preset: 'ts-jest',
testMatch: [
'<rootDir>/**/test/**/?(*.)+(test).ts',
],
...baseConfig,
coverageThreshold: {
global: {
...baseConfig.coverageThreshold.global,
Expand Down
Loading
Loading