Skip to content

Commit 856cb30

Browse files
authored
feat(testing): support jest v30 (#31853)
## Current Behavior Jest v30 is not supported. **Note**: this is currently awaiting for `jest-preset-angular` to support Jest v30: thymikee/jest-preset-angular#3175. ## Expected Behavior Jest v30 should be supported. ## Related Issue(s) Fixes #31778
1 parent 29f9e76 commit 856cb30

File tree

52 files changed

+2524
-610
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2524
-610
lines changed

docs/generated/manifests/new-nx-api.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,6 +2218,36 @@
22182218
}
22192219
},
22202220
"migrations": {
2221+
"/technologies/test-tools/jest/api/migrations/rename-test-path-pattern": {
2222+
"description": "Rename the CLI option `testPathPattern` to `testPathPatterns`.",
2223+
"file": "generated/packages/jest/migrations/rename-test-path-pattern.json",
2224+
"hidden": false,
2225+
"name": "rename-test-path-pattern",
2226+
"version": "21.3.0-beta.3",
2227+
"originalFilePath": "/packages/jest",
2228+
"path": "/technologies/test-tools/jest/api/migrations/rename-test-path-pattern",
2229+
"type": "migration"
2230+
},
2231+
"/technologies/test-tools/jest/api/migrations/replace-removed-matcher-aliases": {
2232+
"description": "Replace removed matcher aliases in Jest v30 with their corresponding matcher",
2233+
"file": "generated/packages/jest/migrations/replace-removed-matcher-aliases.json",
2234+
"hidden": false,
2235+
"name": "replace-removed-matcher-aliases",
2236+
"version": "21.3.0-beta.3",
2237+
"originalFilePath": "/packages/jest",
2238+
"path": "/technologies/test-tools/jest/api/migrations/replace-removed-matcher-aliases",
2239+
"type": "migration"
2240+
},
2241+
"/technologies/test-tools/jest/api/migrations/21.3.0-package-updates": {
2242+
"description": "",
2243+
"file": "generated/packages/jest/migrations/21.3.0-package-updates.json",
2244+
"hidden": false,
2245+
"name": "21.3.0-package-updates",
2246+
"version": "21.3.0-beta.3",
2247+
"originalFilePath": "/packages/jest",
2248+
"path": "/technologies/test-tools/jest/api/migrations/21.3.0-package-updates",
2249+
"type": "migration"
2250+
},
22212251
"/technologies/test-tools/jest/api/migrations/remove-tsconfig-option-from-jest-executor": {
22222252
"description": "Remove the previously deprecated and unused `tsConfig` option from the `@nx/jest:jest` executor.",
22232253
"file": "generated/packages/jest/migrations/remove-tsconfig-option-from-jest-executor.json",

docs/generated/packages-metadata.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/generated/packages/jest/executors/jest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"type": "string"
105105
},
106106
"passWithNoTests": {
107-
"description": "Will not fail if no tests are found (for example while using `--testPathPattern`.) (https://jestjs.io/docs/cli#--passwithnotests)",
107+
"description": "Will not fail if no tests are found (for example while using `--testPathPatterns`.) (https://jestjs.io/docs/cli#--passwithnotests)",
108108
"type": "boolean"
109109
},
110110
"randomize": {
@@ -134,8 +134,8 @@
134134
"type": "array",
135135
"items": { "type": "string" }
136136
},
137-
"testPathPattern": {
138-
"description": "An array of regexp pattern strings that is matched against all tests paths before executing the test. (https://jestjs.io/docs/cli#--testpathpatternregex)",
137+
"testPathPatterns": {
138+
"description": "An array of regexp pattern strings that is matched against all tests paths before executing the test. (https://jestjs.io/docs/cli#--testpathpatternsregex)",
139139
"type": "array",
140140
"items": { "type": "string" },
141141
"default": []
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "21.3.0-package-updates",
3+
"version": "21.3.0-beta.3",
4+
"x-prompt": "Do you want to update the Jest version to v30?",
5+
"packages": {
6+
"jest": { "version": "~30.0.0", "alwaysAddToPackageJson": false },
7+
"@types/jest": { "version": "~30.0.0", "alwaysAddToPackageJson": false },
8+
"expect": { "version": "~30.0.0", "alwaysAddToPackageJson": false },
9+
"@jest/globals": { "version": "~30.0.0", "alwaysAddToPackageJson": false },
10+
"jest-jasmine2": { "version": "~30.0.0", "alwaysAddToPackageJson": false },
11+
"jest-environment-jsdom": {
12+
"version": "~30.0.0",
13+
"alwaysAddToPackageJson": false
14+
},
15+
"babel-jest": { "version": "~30.0.0", "alwaysAddToPackageJson": false },
16+
"@swc/jest": { "version": "~0.2.38", "alwaysAddToPackageJson": false }
17+
},
18+
"aliases": [],
19+
"description": "",
20+
"hidden": false,
21+
"implementation": "",
22+
"path": "/packages/jest",
23+
"schema": null,
24+
"type": "migration"
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "rename-test-path-pattern",
3+
"version": "21.3.0-beta.3",
4+
"requires": { "jest": ">=30.0.0" },
5+
"description": "Rename the CLI option `testPathPattern` to `testPathPatterns`.",
6+
"implementation": "/packages/jest/src/migrations/update-21-3-0/rename-test-path-pattern.ts",
7+
"aliases": [],
8+
"hidden": false,
9+
"path": "/packages/jest",
10+
"schema": null,
11+
"type": "migration",
12+
"examplesFile": "#### Rename `testPathPattern` to `testPathPatterns`\n\nRenames the `testPathPattern` option to `testPathPatterns` in the `@nx/jest:jest` executor configuration to align with Jest v30 CLI changes. Read more at the [Jest v30 migration notes](https://jestjs.io/docs/upgrading-to-jest30#--testpathpattern-was-renamed-to---testpathpatterns).\n\n#### Examples\n\nRename the option in project configuration:\n\n{% tabs %}\n{% tab label=\"Before\" %}\n\n```json {% fileName=\"apps/myapp/project.json\" highlightLines=[7] %}\n{\n \"targets\": {\n \"test\": {\n \"executor\": \"@nx/jest:jest\",\n \"options\": {\n \"jestConfig\": \"apps/myapp/jest.config.ts\",\n \"testPathPattern\": \"some-regex\"\n }\n }\n }\n}\n```\n\n{% /tab %}\n\n{% tab label=\"After\" %}\n\n```json {% fileName=\"apps/myapp/project.json\" highlightLines=[7] %}\n{\n \"targets\": {\n \"test\": {\n \"executor\": \"@nx/jest:jest\",\n \"options\": {\n \"jestConfig\": \"apps/myapp/jest.config.ts\",\n \"testPathPatterns\": \"some-regex\"\n }\n }\n }\n}\n```\n\n{% /tab %}\n{% /tabs %}\n\nRename the option in project configuration with configurations:\n\n{% tabs %}\n{% tab label=\"Before\" %}\n\n```json {% fileName=\"apps/myapp/project.json\" highlightLines=[7,10,11] %}\n{\n \"targets\": {\n \"test\": {\n \"executor\": \"@nx/jest:jest\",\n \"options\": {\n \"jestConfig\": \"apps/myapp/jest.config.ts\",\n \"testPathPattern\": \"some-regex\"\n },\n \"configurations\": {\n \"development\": { \"testPathPattern\": \"regex-dev\" },\n \"production\": { \"testPathPattern\": \"regex-prod\" }\n }\n }\n }\n}\n```\n\n{% /tab %}\n\n{% tab label=\"After\" %}\n\n```json {% fileName=\"apps/myapp/project.json\" highlightLines=[7,10,11] %}\n{\n \"targets\": {\n \"test\": {\n \"executor\": \"@nx/jest:jest\",\n \"options\": {\n \"jestConfig\": \"apps/myapp/jest.config.ts\",\n \"testPathPatterns\": \"some-regex\"\n },\n \"configurations\": {\n \"development\": { \"testPathPatterns\": \"regex-dev\" },\n \"production\": { \"testPathPatterns\": \"regex-prod\" }\n }\n }\n }\n}\n```\n\n{% /tab %}\n{% /tabs %}\n\nRename the option in a target default using the `@nx/jest:jest` executor:\n\n{% tabs %}\n{% tab label=\"Before\" %}\n\n```json {% fileName=\"nx.json\" highlightLines=[7] %}\n{\n \"targetDefaults\": {\n \"test\": {\n \"executor\": \"@nx/jest:jest\",\n \"options\": {\n \"jestConfig\": \"{projectRoot}/jest.config.ts\",\n \"testPathPattern\": \"some-regex\"\n }\n }\n }\n}\n```\n\n{% /tab %}\n\n{% tab label=\"After\" %}\n\n```json {% fileName=\"nx.json\" highlightLines=[7] %}\n{\n \"targetDefaults\": {\n \"test\": {\n \"executor\": \"@nx/jest:jest\",\n \"options\": {\n \"jestConfig\": \"{projectRoot}/jest.config.ts\",\n \"testPathPatterns\": \"some-regex\"\n }\n }\n }\n}\n```\n\n{% /tab %}\n{% /tabs %}\n\nRename the option in a target default using the `@nx/jest:jest` executor as the key:\n\n{% tabs %}\n{% tab label=\"Before\" %}\n\n```json {% fileName=\"nx.json\" highlightLines=[6] %}\n{\n \"targetDefaults\": {\n \"@nx/jest:jest\": {\n \"options\": {\n \"jestConfig\": \"{projectRoot}/jest.config.ts\",\n \"testPathPattern\": \"some-regex\"\n }\n }\n }\n}\n```\n\n{% /tab %}\n\n{% tab label=\"After\" %}\n\n```json {% fileName=\"nx.json\" highlightLines=[6] %}\n{\n \"targetDefaults\": {\n \"@nx/jest:jest\": {\n \"options\": {\n \"jestConfig\": \"{projectRoot}/jest.config.ts\",\n \"testPathPatterns\": \"some-regex\"\n }\n }\n }\n}\n```\n\n{% /tab %}\n{% /tabs %}\n"
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "replace-removed-matcher-aliases",
3+
"version": "21.3.0-beta.3",
4+
"requires": { "jest": ">=30.0.0" },
5+
"description": "Replace removed matcher aliases in Jest v30 with their corresponding matcher",
6+
"implementation": "/packages/jest/src/migrations/update-21-3-0/replace-removed-matcher-aliases.ts",
7+
"aliases": [],
8+
"hidden": false,
9+
"path": "/packages/jest",
10+
"schema": null,
11+
"type": "migration",
12+
"examplesFile": "#### Replace Removed Matcher Aliases\n\nReplaces removed Jest matcher aliases in test files with their corresponding matchers to align with Jest v30 changes. Read more at the [Jest v30 migration notes](https://jestjs.io/docs/upgrading-to-jest30#jest-expect--matchers).\n\n#### Examples\n\n{% tabs %}\n{% tab label=\"Before\" %}\n\n```typescript {% fileName=\"apps/myapp/src/app.spec.ts\" %}\ndescribe('test', () => {\n it('should pass', async () => {\n expect(mockFn).toBeCalled();\n expect(mockFn).toBeCalledTimes(1);\n expect(mockFn).toBeCalledWith(arg);\n expect(mockFn).lastCalledWith(arg);\n expect(mockFn).nthCalledWith(1, arg);\n expect(mockFn).toReturn();\n expect(mockFn).toReturnTimes(1);\n expect(mockFn).toReturnWith(value);\n expect(mockFn).lastReturnedWith(value);\n expect(mockFn).nthReturnedWith(1, value);\n expect(() => someFn()).toThrowError();\n expect(() => someFn()).not.toThrowError();\n await expect(someAsyncFn()).rejects.toThrowError();\n await expect(someAsyncFn()).resolves.not.toThrowError();\n });\n});\n```\n\n{% /tab %}\n\n{% tab label=\"After\" %}\n\n```typescript {% fileName=\"apps/myapp/src/app.spec.ts\" %}\ndescribe('test', () => {\n it('should pass', async () => {\n expect(mockFn).toHaveBeenCalled();\n expect(mockFn).toHaveBeenCalledTimes(1);\n expect(mockFn).toHaveBeenCalledWith(arg);\n expect(mockFn).toHaveBeenLastCalledWith(arg);\n expect(mockFn).toHaveBeenNthCalledWith(1, arg);\n expect(mockFn).toHaveReturned();\n expect(mockFn).toHaveReturnedTimes(1);\n expect(mockFn).toHaveReturnedWith(value);\n expect(mockFn).toHaveLastReturnedWith(value);\n expect(mockFn).toHaveNthReturnedWith(1, value);\n expect(() => someFn()).toThrow();\n expect(() => someFn()).not.toThrow();\n await expect(someAsyncFn()).rejects.toThrow();\n await expect(someAsyncFn()).resolves.not.toThrow();\n });\n});\n```\n\n{% /tab %}\n{% /tabs %}\n"
13+
}

e2e/nx/src/run.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ describe('Nx Running Tests', () => {
155155
expect(success).toContain('0');
156156
expect(success).toContain('1');
157157

158-
expect(() => runCLI(`counter ${myapp} --result=false`)).toThrowError();
158+
expect(() => runCLI(`counter ${myapp} --result=false`)).toThrow();
159159
});
160160

161161
it('should run npm scripts', async () => {

e2e/workspace-create/src/create-nx-workspace-npm.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('create-nx-workspace --preset=npm', () => {
5454

5555
expect(() => {
5656
runCLI(`generate @nx/angular:app packages/${appName} --no-interactive`);
57-
}).not.toThrowError();
57+
}).not.toThrow();
5858
checkFilesExist('tsconfig.base.json');
5959
}, 1_000_000);
6060

@@ -64,7 +64,7 @@ describe('create-nx-workspace --preset=npm', () => {
6464

6565
expect(() => {
6666
runCLI(`generate @nx/angular:lib packages/${libName} --no-interactive`);
67-
}).not.toThrowError();
67+
}).not.toThrow();
6868
checkFilesExist('tsconfig.base.json');
6969
const tsconfig = readJson(`tsconfig.base.json`);
7070
expect(tsconfig.compilerOptions.paths).toEqual({
@@ -79,7 +79,7 @@ describe('create-nx-workspace --preset=npm', () => {
7979

8080
expect(() =>
8181
runCLI(`generate @nx/js:library packages/${libName} --no-interactive`)
82-
).not.toThrowError();
82+
).not.toThrow();
8383
checkFilesExist('tsconfig.base.json');
8484
const tsconfig = readJson(`tsconfig.base.json`);
8585
expect(tsconfig.compilerOptions.paths).toEqual({
@@ -94,7 +94,7 @@ describe('create-nx-workspace --preset=npm', () => {
9494

9595
expect(() =>
9696
runCLI(`generate @nx/web:app packages/${appName} --no-interactive`)
97-
).not.toThrowError();
97+
).not.toThrow();
9898
checkFilesExist('tsconfig.base.json');
9999
});
100100

@@ -105,7 +105,7 @@ describe('create-nx-workspace --preset=npm', () => {
105105

106106
expect(() => {
107107
runCLI(`generate @nx/react:app packages/${appName} --no-interactive`);
108-
}).not.toThrowError();
108+
}).not.toThrow();
109109
checkFilesExist('tsconfig.base.json');
110110
});
111111

@@ -116,7 +116,7 @@ describe('create-nx-workspace --preset=npm', () => {
116116

117117
expect(() => {
118118
runCLI(`generate @nx/react:lib packages/${libName} --no-interactive`);
119-
}).not.toThrowError();
119+
}).not.toThrow();
120120
checkFilesExist('tsconfig.base.json');
121121
const tsconfig = readJson(`tsconfig.base.json`);
122122
expect(tsconfig.compilerOptions.paths).toEqual({
@@ -131,7 +131,7 @@ describe('create-nx-workspace --preset=npm', () => {
131131

132132
expect(() => {
133133
runCLI(`generate @nx/next:app packages/${appName} --no-interactive`);
134-
}).not.toThrowError();
134+
}).not.toThrow();
135135
checkFilesExist('tsconfig.base.json');
136136
});
137137

@@ -142,7 +142,7 @@ describe('create-nx-workspace --preset=npm', () => {
142142

143143
expect(() => {
144144
runCLI(`generate @nx/next:lib packages/${libName} --no-interactive`);
145-
}).not.toThrowError();
145+
}).not.toThrow();
146146
checkFilesExist('tsconfig.base.json');
147147
const tsconfig = readJson(`tsconfig.base.json`);
148148
expect(tsconfig.compilerOptions.paths).toEqual({
@@ -160,7 +160,7 @@ describe('create-nx-workspace --preset=npm', () => {
160160
runCLI(
161161
`generate @nx/react-native:app packages/${appName} --install=false --no-interactive`
162162
);
163-
}).not.toThrowError();
163+
}).not.toThrow();
164164
checkFilesExist('tsconfig.base.json');
165165
});
166166

@@ -173,7 +173,7 @@ describe('create-nx-workspace --preset=npm', () => {
173173
runCLI(
174174
`generate @nx/react-native:lib packages/${libName} --no-interactive`
175175
);
176-
}).not.toThrowError();
176+
}).not.toThrow();
177177
checkFilesExist('tsconfig.base.json');
178178
const tsconfig = readJson(`tsconfig.base.json`);
179179
expect(tsconfig.compilerOptions.paths).toEqual({
@@ -188,7 +188,7 @@ describe('create-nx-workspace --preset=npm', () => {
188188

189189
expect(() => {
190190
runCLI(`generate @nx/node:app packages/${appName} --no-interactive`);
191-
}).not.toThrowError();
191+
}).not.toThrow();
192192
checkFilesExist('tsconfig.base.json');
193193
});
194194

@@ -199,7 +199,7 @@ describe('create-nx-workspace --preset=npm', () => {
199199

200200
expect(() => {
201201
runCLI(`generate @nx/node:lib packages/${libName} --no-interactive`);
202-
}).not.toThrowError();
202+
}).not.toThrow();
203203
checkFilesExist('tsconfig.base.json');
204204
const tsconfig = readJson(`tsconfig.base.json`);
205205
expect(tsconfig.compilerOptions.paths).toEqual({
@@ -214,7 +214,7 @@ describe('create-nx-workspace --preset=npm', () => {
214214

215215
expect(() => {
216216
runCLI(`generate @nx/nest:app packages/${appName} --no-interactive`);
217-
}).not.toThrowError();
217+
}).not.toThrow();
218218
checkFilesExist('tsconfig.base.json');
219219
});
220220

@@ -225,7 +225,7 @@ describe('create-nx-workspace --preset=npm', () => {
225225

226226
expect(() => {
227227
runCLI(`generate @nx/nest:lib packages/${libName} --no-interactive`);
228-
}).not.toThrowError();
228+
}).not.toThrow();
229229
checkFilesExist('tsconfig.base.json');
230230
const tsconfig = readJson(`tsconfig.base.json`);
231231
expect(tsconfig.compilerOptions.paths).toEqual({
@@ -240,7 +240,7 @@ describe('create-nx-workspace --preset=npm', () => {
240240

241241
expect(() => {
242242
runCLI(`generate @nx/express:app packages/${appName} --no-interactive`);
243-
}).not.toThrowError();
243+
}).not.toThrow();
244244
checkFilesExist('tsconfig.base.json');
245245
});
246246
});

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
"@floating-ui/react": "0.26.6",
6161
"@iconify-json/ph": "^1.1.12",
6262
"@iconify-json/svg-spinners": "^1.1.2",
63-
"@jest/reporters": "29.7.0",
64-
"@jest/test-result": "29.7.0",
65-
"@jest/types": "29.6.3",
63+
"@jest/reporters": "30.0.2",
64+
"@jest/test-result": "30.0.2",
65+
"@jest/types": "30.0.1",
6666
"@ltd/j-toml": "^1.38.0",
6767
"@module-federation/enhanced": "^0.15.0",
6868
"@module-federation/sdk": "^0.15.0",
@@ -131,7 +131,7 @@
131131
"@swc/cli": "0.6.0",
132132
"@swc/core": "1.5.7",
133133
"@swc/helpers": "0.5.11",
134-
"@swc/jest": "0.2.36",
134+
"@swc/jest": "0.2.38",
135135
"@testing-library/react": "15.0.6",
136136
"@tutorialkit/astro": "1.5.0",
137137
"@tutorialkit/react": "1.5.0",
@@ -148,7 +148,7 @@
148148
"@types/is-ci": "^3.0.0",
149149
"@types/jasmine": "~2.8.6",
150150
"@types/jasminewd2": "~2.0.3",
151-
"@types/jest": "29.5.12",
151+
"@types/jest": "30.0.0",
152152
"@types/js-yaml": "^4.0.9",
153153
"@types/marked": "^2.0.0",
154154
"@types/node": "20.16.10",
@@ -177,7 +177,7 @@
177177
"angular-eslint": "20.0.0",
178178
"astro": "4.15.0",
179179
"autoprefixer": "10.4.13",
180-
"babel-jest": "29.7.0",
180+
"babel-jest": "30.0.2",
181181
"babel-loader": "^9.1.2",
182182
"browserslist": "^4.21.4",
183183
"chalk": "^4.1.0",
@@ -236,14 +236,14 @@
236236
"is-windows": "^1.0.2",
237237
"jasmine-core": "~2.99.1",
238238
"jasmine-spec-reporter": "~4.2.1",
239-
"jest": "29.7.0",
240-
"jest-config": "29.7.0",
241-
"jest-diff": "29.7.0",
242-
"jest-environment-jsdom": "29.7.0",
243-
"jest-environment-node": "29.7.0",
244-
"jest-resolve": "29.7.0",
245-
"jest-runtime": "29.7.0",
246-
"jest-util": "29.7.0",
239+
"jest": "30.0.2",
240+
"jest-config": "30.0.2",
241+
"jest-diff": "30.0.2",
242+
"jest-environment-jsdom": "30.0.2",
243+
"jest-environment-node": "30.0.2",
244+
"jest-resolve": "30.0.2",
245+
"jest-runtime": "30.0.2",
246+
"jest-util": "30.0.2",
247247
"js-tokens": "^4.0.0",
248248
"js-yaml": "^4.1.0",
249249
"jsonc-eslint-parser": "^2.1.0",
@@ -313,7 +313,7 @@
313313
"tinyglobby": "^0.2.10",
314314
"tmp": "~0.2.1",
315315
"tree-kill": "1.2.2",
316-
"ts-jest": "29.1.0",
316+
"ts-jest": "^29.4.0",
317317
"ts-loader": "^9.3.1",
318318
"ts-node": "10.9.1",
319319
"ts-checker-rspack-plugin": "^1.1.1",

0 commit comments

Comments
 (0)