Skip to content

Commit

Permalink
chore: upgrade jest to 29 (#2747)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilch authored Aug 30, 2024
1 parent a1d1620 commit 38de325
Show file tree
Hide file tree
Showing 60 changed files with 2,143 additions and 3,936 deletions.
19 changes: 0 additions & 19 deletions FixJestEnvironment.js

This file was deleted.

7 changes: 1 addition & 6 deletions client-test-apps/js/api-model-relationship-app/package.json
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"
}
}
}
872 changes: 512 additions & 360 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
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
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

0 comments on commit 38de325

Please sign in to comment.