@nx/jest 23.0.0-beta.17 → 23.0.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ #### Replace Usage of `getJestProjects` with `getJestProjectsAsync`
2
+
3
+ Replaces the usage of the deprecated `getJestProjects` function with the `getJestProjectsAsync` function.
4
+
5
+ #### Sample Code Changes
6
+
7
+ ##### Before
8
+
9
+ ```ts title="jest.config.ts"
10
+ import { getJestProjects } from '@nx/jest';
11
+
12
+ export default {
13
+ projects: getJestProjects(),
14
+ };
15
+ ```
16
+
17
+ ##### After
18
+
19
+ ```ts title="jest.config.ts"
20
+ import { getJestProjectsAsync } from '@nx/jest';
21
+
22
+ export default async () => ({
23
+ projects: await getJestProjectsAsync(),
24
+ });
25
+ ```
@@ -0,0 +1,102 @@
1
+ #### Remove `tsConfig` Option from Jest Executor
2
+
3
+ Removes the previously deprecated and unused `tsConfig` option from the `@nx/jest:jest` executor configuration in all projects.
4
+
5
+ #### Examples
6
+
7
+ Remove the option from the project configuration:
8
+
9
+ ##### Before
10
+
11
+ ```json title="apps/myapp/project.json" {7}
12
+ {
13
+ "targets": {
14
+ "test": {
15
+ "executor": "@nx/jest:jest",
16
+ "options": {
17
+ "jestConfig": "apps/myapp/jest.config.ts",
18
+ "tsConfig": "apps/myapp/tsconfig.spec.json"
19
+ }
20
+ }
21
+ }
22
+ }
23
+ ```
24
+
25
+ ##### After
26
+
27
+ ```json title="apps/myapp/project.json"
28
+ {
29
+ "targets": {
30
+ "test": {
31
+ "executor": "@nx/jest:jest",
32
+ "options": {
33
+ "jestConfig": "apps/myapp/jest.config.ts"
34
+ }
35
+ }
36
+ }
37
+ }
38
+ ```
39
+
40
+ Remove the option from a target default using the `@nx/jest:jest` executor:
41
+
42
+ ##### Before
43
+
44
+ ```json title="nx.json" {7}
45
+ {
46
+ "targetDefaults": {
47
+ "test": {
48
+ "executor": "@nx/jest:jest",
49
+ "options": {
50
+ "jestConfig": "{projectRoot}/jest.config.ts",
51
+ "tsConfig": "{projectRoot}/tsconfig.spec.json"
52
+ }
53
+ }
54
+ }
55
+ }
56
+ ```
57
+
58
+ ##### After
59
+
60
+ ```json title="nx.json"
61
+ {
62
+ "targetDefaults": {
63
+ "test": {
64
+ "executor": "@nx/jest:jest",
65
+ "options": {
66
+ "jestConfig": "{projectRoot}/jest.config.ts"
67
+ }
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ Remove the option from a target default using the `@nx/jest:jest` executor as the key:
74
+
75
+ ##### Before
76
+
77
+ ```json title="nx.json" {6}
78
+ {
79
+ "targetDefaults": {
80
+ "@nx/jest:jest": {
81
+ "options": {
82
+ "jestConfig": "{projectRoot}/jest.config.ts",
83
+ "tsConfig": "{projectRoot}/tsconfig.spec.json"
84
+ }
85
+ }
86
+ }
87
+ }
88
+ ```
89
+
90
+ ##### After
91
+
92
+ ```json title="nx.json"
93
+ {
94
+ "targetDefaults": {
95
+ "@nx/jest:jest": {
96
+ "options": {
97
+ "jestConfig": "{projectRoot}/jest.config.ts"
98
+ }
99
+ }
100
+ }
101
+ }
102
+ ```
@@ -0,0 +1,25 @@
1
+ #### Replace Usage of `getJestProjects` with `getJestProjectsAsync`
2
+
3
+ Replaces the usage of the removed `getJestProjects` function with the `getJestProjectsAsync` function.
4
+
5
+ #### Sample Code Changes
6
+
7
+ ##### Before
8
+
9
+ ```ts title="jest.config.ts"
10
+ import { getJestProjects } from '@nx/jest';
11
+
12
+ export default {
13
+ projects: getJestProjects(),
14
+ };
15
+ ```
16
+
17
+ ##### After
18
+
19
+ ```ts title="jest.config.ts"
20
+ import { getJestProjectsAsync } from '@nx/jest';
21
+
22
+ export default async () => ({
23
+ projects: await getJestProjectsAsync(),
24
+ });
25
+ ```
@@ -0,0 +1,147 @@
1
+ #### Rename `testPathPattern` to `testPathPatterns`
2
+
3
+ Renames 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).
4
+
5
+ #### Examples
6
+
7
+ Rename the option in project configuration:
8
+
9
+ ##### Before
10
+
11
+ ```json title="apps/myapp/project.json" {7}
12
+ {
13
+ "targets": {
14
+ "test": {
15
+ "executor": "@nx/jest:jest",
16
+ "options": {
17
+ "jestConfig": "apps/myapp/jest.config.ts",
18
+ "testPathPattern": "some-regex"
19
+ }
20
+ }
21
+ }
22
+ }
23
+ ```
24
+
25
+ ##### After
26
+
27
+ ```json title="apps/myapp/project.json" {7}
28
+ {
29
+ "targets": {
30
+ "test": {
31
+ "executor": "@nx/jest:jest",
32
+ "options": {
33
+ "jestConfig": "apps/myapp/jest.config.ts",
34
+ "testPathPatterns": "some-regex"
35
+ }
36
+ }
37
+ }
38
+ }
39
+ ```
40
+
41
+ Rename the option in project configuration with configurations:
42
+
43
+ ##### Before
44
+
45
+ ```json title="apps/myapp/project.json" {7,10,11}
46
+ {
47
+ "targets": {
48
+ "test": {
49
+ "executor": "@nx/jest:jest",
50
+ "options": {
51
+ "jestConfig": "apps/myapp/jest.config.ts",
52
+ "testPathPattern": "some-regex"
53
+ },
54
+ "configurations": {
55
+ "development": { "testPathPattern": "regex-dev" },
56
+ "production": { "testPathPattern": "regex-prod" }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ ##### After
64
+
65
+ ```json title="apps/myapp/project.json" {7,10,11}
66
+ {
67
+ "targets": {
68
+ "test": {
69
+ "executor": "@nx/jest:jest",
70
+ "options": {
71
+ "jestConfig": "apps/myapp/jest.config.ts",
72
+ "testPathPatterns": "some-regex"
73
+ },
74
+ "configurations": {
75
+ "development": { "testPathPatterns": "regex-dev" },
76
+ "production": { "testPathPatterns": "regex-prod" }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ Rename the option in a target default using the `@nx/jest:jest` executor:
84
+
85
+ ##### Before
86
+
87
+ ```json title="nx.json" {7}
88
+ {
89
+ "targetDefaults": {
90
+ "test": {
91
+ "executor": "@nx/jest:jest",
92
+ "options": {
93
+ "jestConfig": "{projectRoot}/jest.config.ts",
94
+ "testPathPattern": "some-regex"
95
+ }
96
+ }
97
+ }
98
+ }
99
+ ```
100
+
101
+ ##### After
102
+
103
+ ```json title="nx.json" {7}
104
+ {
105
+ "targetDefaults": {
106
+ "test": {
107
+ "executor": "@nx/jest:jest",
108
+ "options": {
109
+ "jestConfig": "{projectRoot}/jest.config.ts",
110
+ "testPathPatterns": "some-regex"
111
+ }
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ Rename the option in a target default using the `@nx/jest:jest` executor as the key:
118
+
119
+ ##### Before
120
+
121
+ ```json title="nx.json" {6}
122
+ {
123
+ "targetDefaults": {
124
+ "@nx/jest:jest": {
125
+ "options": {
126
+ "jestConfig": "{projectRoot}/jest.config.ts",
127
+ "testPathPattern": "some-regex"
128
+ }
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ ##### After
135
+
136
+ ```json title="nx.json" {6}
137
+ {
138
+ "targetDefaults": {
139
+ "@nx/jest:jest": {
140
+ "options": {
141
+ "jestConfig": "{projectRoot}/jest.config.ts",
142
+ "testPathPatterns": "some-regex"
143
+ }
144
+ }
145
+ }
146
+ }
147
+ ```
@@ -0,0 +1,51 @@
1
+ #### Replace Removed Matcher Aliases
2
+
3
+ Replaces 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).
4
+
5
+ #### Examples
6
+
7
+ ##### Before
8
+
9
+ ```typescript title="apps/myapp/src/app.spec.ts"
10
+ describe('test', () => {
11
+ it('should pass', async () => {
12
+ expect(mockFn).toBeCalled();
13
+ expect(mockFn).toBeCalledTimes(1);
14
+ expect(mockFn).toBeCalledWith(arg);
15
+ expect(mockFn).lastCalledWith(arg);
16
+ expect(mockFn).nthCalledWith(1, arg);
17
+ expect(mockFn).toReturn();
18
+ expect(mockFn).toReturnTimes(1);
19
+ expect(mockFn).toReturnWith(value);
20
+ expect(mockFn).lastReturnedWith(value);
21
+ expect(mockFn).nthReturnedWith(1, value);
22
+ expect(() => someFn()).toThrowError();
23
+ expect(() => someFn()).not.toThrowError();
24
+ await expect(someAsyncFn()).rejects.toThrowError();
25
+ await expect(someAsyncFn()).resolves.not.toThrowError();
26
+ });
27
+ });
28
+ ```
29
+
30
+ ##### After
31
+
32
+ ```typescript title="apps/myapp/src/app.spec.ts"
33
+ describe('test', () => {
34
+ it('should pass', async () => {
35
+ expect(mockFn).toHaveBeenCalled();
36
+ expect(mockFn).toHaveBeenCalledTimes(1);
37
+ expect(mockFn).toHaveBeenCalledWith(arg);
38
+ expect(mockFn).toHaveBeenLastCalledWith(arg);
39
+ expect(mockFn).toHaveBeenNthCalledWith(1, arg);
40
+ expect(mockFn).toHaveReturned();
41
+ expect(mockFn).toHaveReturnedTimes(1);
42
+ expect(mockFn).toHaveReturnedWith(value);
43
+ expect(mockFn).toHaveLastReturnedWith(value);
44
+ expect(mockFn).toHaveNthReturnedWith(1, value);
45
+ expect(() => someFn()).toThrow();
46
+ expect(() => someFn()).not.toThrow();
47
+ await expect(someAsyncFn()).rejects.toThrow();
48
+ await expect(someAsyncFn()).resolves.not.toThrow();
49
+ });
50
+ });
51
+ ```
@@ -0,0 +1,33 @@
1
+ #### Convert Jest Config to CJS
2
+
3
+ Converts `jest.config.ts` files to `jest.config.cts`. This is needed because Node.js type-stripping in newer versions (22+, 24+) can cause issues with ESM syntax in `.ts` files when the project is configured for CommonJS.
4
+
5
+ This migration only runs if `@nx/jest/plugin` is registered in `nx.json`.
6
+
7
+ #### Examples
8
+
9
+ ##### Before
10
+
11
+ ```typescript title="jest.config.ts"
12
+ import { foo } from 'bar';
13
+ import baz from 'qux';
14
+
15
+ export default {
16
+ displayName: 'myapp',
17
+ preset: foo,
18
+ transform: baz,
19
+ };
20
+ ```
21
+
22
+ ##### After
23
+
24
+ ```typescript title="jest.config.cts"
25
+ const { foo } = require('bar');
26
+ const baz = require('qux').default ?? require('qux');
27
+
28
+ module.exports = {
29
+ displayName: 'myapp',
30
+ preset: foo,
31
+ transform: baz,
32
+ };
33
+ ```
@@ -148,19 +148,34 @@ function collectCallExpressionRewrites(sourceFile, changes) {
148
148
  // internal entry.
149
149
  replaceSpecifier(sourceFile, node.arguments[0], TO_INTERNAL, changes);
150
150
  }
151
+ else if (ts.isImportTypeNode(node)) {
152
+ // `typeof import('...')` parses as an `ImportTypeNode`, not a
153
+ // CallExpression — its argument is `LiteralTypeNode<StringLiteral>`.
154
+ // The whole module is referenced, so it can't be symbol-split.
155
+ const literal = getImportTypeStringLiteral(node);
156
+ if (literal && literal.text.startsWith(FROM_PREFIX)) {
157
+ replaceSpecifier(sourceFile, literal, TO_INTERNAL, changes);
158
+ }
159
+ }
151
160
  ts.forEachChild(node, visit);
152
161
  };
153
162
  visit(sourceFile);
154
163
  }
164
+ function getImportTypeStringLiteral(node) {
165
+ const arg = node.argument;
166
+ if (arg && ts.isLiteralTypeNode(arg) && ts.isStringLiteral(arg.literal)) {
167
+ return arg.literal;
168
+ }
169
+ return undefined;
170
+ }
155
171
  function shouldRewriteCallExpression(call) {
156
172
  const callee = call.expression;
157
173
  // `require('...')`
158
174
  if (ts.isIdentifier(callee) && callee.text === 'require')
159
175
  return true;
160
176
  // dynamic `import('...')` (runtime form parses as a CallExpression whose
161
- // callee is the `import` keyword). The type-position form
162
- // (`typeof import('...')`) is an `ImportTypeNode`, not a CallExpression, so
163
- // we don't touch it.
177
+ // callee is the `import` keyword). The `typeof import('...')` type-position
178
+ // form is an `ImportTypeNode` (handled in `collectCallExpressionRewrites`).
164
179
  if (callee.kind === ts.SyntaxKind.ImportKeyword)
165
180
  return true;
166
181
  // `jest.mock(...)` / `vi.mock(...)` and friends.
@@ -0,0 +1,21 @@
1
+ #### Update Jest Snapshot Guide Link
2
+
3
+ Updates the snapshot guide link at the top of every `.snap` file from the legacy `https://goo.gl/fbAQLP` to `https://jestjs.io/docs/snapshot-testing`. Jest v30 errors out at test setup time if it sees the old link, so existing snapshot files need to be rewritten before tests can run. Read more at the [Jest v30 migration notes](https://jestjs.io/docs/upgrading-to-jest30).
4
+
5
+ #### Examples
6
+
7
+ ##### Before
8
+
9
+ ```text title="apps/myapp/src/__snapshots__/example.spec.ts.snap"
10
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
11
+
12
+ exports[`renders correctly 1`] = `"hello"`;
13
+ ```
14
+
15
+ ##### After
16
+
17
+ ```text title="apps/myapp/src/__snapshots__/example.spec.ts.snap"
18
+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
19
+
20
+ exports[`renders correctly 1`] = `"hello"`;
21
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/jest",
3
- "version": "23.0.0-beta.17",
3
+ "version": "23.0.0-beta.19",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -104,11 +104,11 @@
104
104
  "semver": "^7.6.3",
105
105
  "tslib": "^2.3.0",
106
106
  "yargs-parser": "21.1.1",
107
- "@nx/devkit": "23.0.0-beta.17",
108
- "@nx/js": "23.0.0-beta.17"
107
+ "@nx/devkit": "23.0.0-beta.19",
108
+ "@nx/js": "23.0.0-beta.19"
109
109
  },
110
110
  "devDependencies": {
111
- "nx": "23.0.0-beta.17"
111
+ "nx": "23.0.0-beta.19"
112
112
  },
113
113
  "publishConfig": {
114
114
  "access": "public"