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: upgrade jest to 29 #2747

Merged
merged 26 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3770c1f
chore: upgrade jest to 29
dpilch Aug 2, 2024
04edf59
test: remove unnecessary structuredClone fix
dpilch Aug 5, 2024
e516dce
test: fix cli test environment
dpilch Aug 5, 2024
61d78f3
test: remove axios from jest.moduleNameMapper
dpilch Aug 5, 2024
3b36683
test: fix jest config
dpilch Aug 6, 2024
0973633
test: fix jest config
dpilch Aug 14, 2024
ded0cbb
chore: extract dependency licenses
dpilch Aug 9, 2024
163ff7d
test: use testEnvironmentOptions.url
dpilch Aug 12, 2024
7e40b10
test: increase retry timeout to 25 minutes
dpilch Aug 12, 2024
6c4c044
style: run prettier
dpilch Aug 14, 2024
d11d392
test: lower e2e test max workers to 3
dpilch Aug 13, 2024
072d7ea
test: lower jest max workers to 3
dpilch Aug 14, 2024
181662a
test: increase jest default timeout
dpilch Aug 14, 2024
7cd733d
test: fix jest.setTimeout bug
dpilch Aug 14, 2024
0ad5bf6
chore: upgrade @types/node to ^18.0.0
dpilch Aug 23, 2024
f0c466f
ci: get node version
dpilch Aug 27, 2024
f3bac70
ci: increase compute-type to large and increase max-old-space-size
dpilch Aug 27, 2024
3f2bf5b
ci: move NODE_options to variables
dpilch Aug 27, 2024
5f14bda
ci: remove unused variables
dpilch Aug 27, 2024
34c8148
Revert "test: lower jest max workers to 3"
dpilch Aug 27, 2024
d88912b
Revert "test: lower e2e test max workers to 3"
dpilch Aug 27, 2024
34a945e
ci: increase max workers to 5
dpilch Aug 27, 2024
49ab1e0
ci: set non-test process memory to 0.5GB
dpilch Aug 27, 2024
049e015
ci: actually set max workers to 5
dpilch Aug 28, 2024
160d3bb
Merge branch 'main' into jest-upgrade
dpilch Aug 30, 2024
421f754
docs: fix comment to use correct instance size
dpilch Aug 30, 2024
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
19 changes: 0 additions & 19 deletions FixJestEnvironment.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@types/ini": "^1.3.31",
"@types/jest": "^27.5.2",
"@types/jest-dev-server": "^5.0.0",
"@types/node": "^16.11.56",
"@types/node": "^18.0.0",
"@types/react": "18.2.42",
"@types/react-dom": "^18.0.6",
"aws-amplify": "^4.3.30",
Expand Down Expand Up @@ -64,10 +64,5 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"jest": {
"moduleNameMapper": {
"axios": "axios/dist/node/axios.cjs"
}
}
}
874 changes: 513 additions & 361 deletions codebuild_specs/e2e_workflow.yml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion codebuild_specs/run_cdk_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ env:
AMPLIFY_PATH: /root/.npm-global/lib/node_modules/@aws-amplify/cli-internal/bin/amplify
CI: true
CODEBUILD: true
NODE_OPTIONS: --max-old-space-size=8096
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were ignored.

phases:
build:
commands:
Expand Down
1 change: 0 additions & 1 deletion codebuild_specs/run_e2e_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ env:
AMPLIFY_PATH: /root/.npm-global/lib/node_modules/@aws-amplify/cli-internal/bin/amplify
CI: true
CODEBUILD: true
NODE_OPTIONS: --max-old-space-size=8096
phases:
build:
commands:
Expand Down
2,357 changes: 462 additions & 1,895 deletions dependency_licenses.txt

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
"@commitlint/prompt": "^16.2.3",
"@microsoft/api-extractor": "^7.33.5",
"@types/glob": "^7.1.1",
"@types/jest": "^26.0.20",
"@types/jest": "^29.0.0",
"@types/js-yaml": "^4.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
Expand All @@ -218,16 +218,16 @@
"execa": "^5.1.1",
"glob": "^10.3.0",
"husky": "^3.0.3",
"jest": "^26.6.2",
"jest-circus": "^26.6.2",
"jest": "^29.0.0",
"jest-circus": "^29.0.0",
"jest-junit": "^12.0.0",
"js-yaml": "^4.0.0",
"lint-staged": "^13.2.2",
"lnk": "1.1.0",
"pkg": "^5.4.1",
"prettier": "^2.8.8",
"rimraf": "^3.0.0",
"ts-jest": "^26.4.4",
"ts-jest": "^29.0.0",
"ts-node": "^8.10.1",
"typescript": "^4.5.5"
},
Expand All @@ -247,10 +247,6 @@
"ejs": "^3.1.7",
"json5": "^2.2.3",
"semver": "^7.5.2",
"jest": "26.6.2",
"jest-environment-jsdom": "26.6.2",
"jest-environment-node": "26.6.2",
"ts-jest": "^26.5.5",
"axios": "^1.7.4",
"braces": "^3.0.3"
}
Expand Down
15 changes: 10 additions & 5 deletions packages/amplify-data-construct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@
},
"devDependencies": {
"@types/fs-extra": "^8.0.1",
"@types/node": "^12.12.6",
"@types/node": "^18.0.0",
"aws-cdk-lib": "2.152.0",
"constructs": "10.3.0",
"jsii": "^5.4.23",
"jsii-pacmak": "^1.84.0",
"rimraf": "^3.0.0",
"ts-jest": "^26.4.4",
"ts-jest": "^29.0.0",
"ts-node": "^8.10.1"
},
"peerDependencies": {
Expand All @@ -143,7 +143,9 @@
}
},
"jest": {
"testURL": "http://localhost",
"testEnvironmentOptions": {
"url": "http://localhost"
},
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
Expand All @@ -169,12 +171,15 @@
"clover",
"text"
],
"testEnvironment": "../../FixJestEnvironment.js",
"collectCoverageFrom": [
"src/**/*.ts"
],
"coveragePathIgnorePatterns": [
"/__tests__/"
]
],
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
}
}
}
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"glob": "^10.3.0",
"graphql-transformer-core": "9.0.0",
"ini": "^3.0.1",
"jest-environment-node": "^26.6.2",
"jest-environment-node": "^29.0.0",
"knex": "~2.4.0",
"lodash": "^4.17.21",
"mysql2": "~3.9.7",
Expand Down
10 changes: 1 addition & 9 deletions packages/amplify-e2e-core/src/cli-test-environment.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
const NodeEnvironment = require('jest-environment-node');
const NodeEnvironment = require('jest-environment-node').TestEnvironment;

class CLIEnvironment extends NodeEnvironment {
constructor(config, context) {
super(config, context);

// https://github.com/jestjs/jest/issues/12628
// structuredClone is missing in the jest node environment.
// Newer versions of jest have fixed this, but is not possible to upgrade at this time.
// Newer versions of jest have a performance issue when not used with Node ^20.11.0
// https://github.com/jestjs/jest/issues/11956
// Our minimum supported version is Node 18.
this.global.structuredClone = structuredClone;

this.testPath = context.testPath;
this.testLogStack = [];
this.describeBlocks = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/utils/retrier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { sleep } from './sleep';
const defaultSettings: RetrySettings = {
times: Infinity,
delayMS: 1000 * 10, // 10 seconds
timeoutMS: 1000 * 60 * 20, // 20 minutes
timeoutMS: 1000 * 60 * 25, // 25 minutes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you encounter that caused the bump from 20 to 25 minutes on the timeout?

I would guess this means our e2e tests slowed down by ~25%, which might be enough to be worth an investigation. If you have already done the investigation, whats driving the increase and can we do better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a performance degradation with newer versions of Jest when run with node < 20 (jestjs/jest#11956). We currently support Node 18. Node 18 will be EOL in 8 months, so we should look into upgrading to Node 20.

stopOnError: true, // terminate the retries if a func calls throws an exception
};

Expand Down
23 changes: 15 additions & 8 deletions packages/amplify-e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@
"testRunner": "amplify-category-api-e2e-core/runner",
"testEnvironment": "amplify-category-api-e2e-core/environment",
"transform": {
"^.+\\.tsx?$": "ts-jest"
"^.+\\.tsx?$": [
"ts-jest",
{
"diagnostics": false
}
]
},
"testEnvironmentOptions": {
"url": "http://localhost"
},
"testURL": "http://localhost",
"testRegex": "(src/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"testPathIgnorePatterns": [
"/node_modules/",
Expand Down Expand Up @@ -106,19 +113,19 @@
"<rootDir>/src/setup-tests.ts"
],
"globals": {
"window": {},
"ts-jest": {
"diagnostics": false
}
"window": {}
},
"moduleNameMapper": {
"axios": "axios/dist/node/axios.cjs",
"^csv-parse/sync": "<rootDir>/../../node_modules/csv-parse/dist/cjs/sync.cjs"
},
"coveragePathIgnorePatterns": [
"/node_modules/",
"/__tests__/"
]
],
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
}
},
"jest-junit": {
"outputDirectory": "reports/junit/",
Expand Down
27 changes: 16 additions & 11 deletions packages/amplify-graphql-api-construct-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"devDependencies": {
"@aws-amplify/graphql-transformer-core": "3.0.1",
"@aws-amplify/graphql-transformer-interfaces": "4.0.1",
"@types/node": "^16.11.56",
"@types/node": "^18.0.0",
"aws-cdk-lib": "2.152.0",
"constructs": "10.3.0",
"ts-node": "^8.10.2"
Expand All @@ -55,9 +55,16 @@
"testRunner": "amplify-category-api-e2e-core/runner",
"testEnvironment": "amplify-category-api-e2e-core/environment",
"transform": {
"^.+\\.tsx?$": "ts-jest"
"^.+\\.tsx?$": [
"ts-jest",
{
"diagnostics": false
}
]
},
"testEnvironmentOptions": {
"url": "http://localhost"
},
"testURL": "http://localhost",
"testRegex": "(src/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"testPathIgnorePatterns": [
"/node_modules/",
Expand Down Expand Up @@ -95,18 +102,16 @@
"node"
],
"globals": {
"window": {},
"ts-jest": {
"diagnostics": false
}
},
"moduleNameMapper": {
"axios": "axios/dist/node/axios.cjs"
"window": {}
},
"coveragePathIgnorePatterns": [
"/__tests__/",
"/node_modules/"
]
],
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
}
},
"jest-junit": {
"outputDirectory": "reports/junit/",
Expand Down
19 changes: 12 additions & 7 deletions packages/amplify-graphql-api-construct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@
"devDependencies": {
"@aws-amplify/graphql-transformer-test-utils": "0.6.1",
"@types/fs-extra": "^8.0.1",
"@types/node": "^12.12.6",
"@types/node": "^18.0.0",
"aws-cdk-lib": "2.152.0",
"constructs": "10.3.0",
"jsii": "^5.4.23",
"jsii-docgen": "9.1.2",
"jsii-pacmak": "^1.84.0",
"rimraf": "^3.0.0",
"ts-jest": "^26.4.4",
"ts-jest": "^29.0.0",
"ts-node": "^8.10.1"
},
"peerDependencies": {
Expand All @@ -145,7 +145,9 @@
}
},
"jest": {
"testURL": "http://localhost",
"testEnvironmentOptions": {
"url": "http://localhost"
},
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
Expand All @@ -162,21 +164,24 @@
"coverageProvider": "v8",
"coverageThreshold": {
"global": {
"branches": 90,
"branches": 89,
"functions": 90,
"lines": 59
"lines": 58
}
},
"coverageReporters": [
"clover",
"text"
],
"testEnvironment": "../../FixJestEnvironment.js",
"collectCoverageFrom": [
"src/**/*.ts"
],
"coveragePathIgnorePatterns": [
"/__tests__/"
]
],
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
}
}
}
13 changes: 9 additions & 4 deletions packages/amplify-graphql-auth-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
"@aws-amplify/graphql-searchable-transformer": "3.0.1",
"@aws-amplify/graphql-sql-transformer": "0.4.1",
"@aws-amplify/graphql-transformer-test-utils": "0.6.1",
"@types/node": "^12.12.6"
"@types/node": "^18.0.0"
},
"peerDependencies": {
"aws-cdk-lib": "^2.152.0",
"constructs": "^10.3.0"
},
"jest": {
"testURL": "http://localhost",
"testEnvironmentOptions": {
"url": "http://localhost"
},
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
Expand All @@ -80,12 +82,15 @@
"clover",
"text"
],
"testEnvironment": "../../FixJestEnvironment.js",
"collectCoverageFrom": [
"src/**/*.ts"
],
"coveragePathIgnorePatterns": [
"/__tests__/"
]
],
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ are writing a new snapshot test, here are a few points to keep in mind:
snapshot test:
```ts
const fakeDate = Date.UTC(2024, 0, 1, 0, 0, 0);
jest.useFakeTimers('modern');
jest.useFakeTimers();
jest.setSystemTime(fakeDate);
```
- Some resources use local filesystem paths. If these are not important to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Auth operation combinations: custom mutations', () => {
beforeEach(() => {
// Fix all Date.now() calls to 1704067200000 epoch milliseconds
const fakeDate = Date.UTC(2024, 0, 1, 0, 0, 0);
jest.useFakeTimers('modern');
jest.useFakeTimers();
jest.setSystemTime(fakeDate);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Auth operation combinations: model', () => {
beforeEach(() => {
// Fix all Date.now() calls to 1704067200000 epoch milliseconds
const fakeDate = Date.UTC(2024, 0, 1, 0, 0, 0);
jest.useFakeTimers('modern');
jest.useFakeTimers();
jest.setSystemTime(fakeDate);
});

Expand Down
Loading
Loading