@nx/jest 23.1.0 → 23.1.2
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.
- package/dist/src/executors/jest/jest.impl.d.ts +1 -1
- package/dist/src/generators/configuration/lib/create-jest-config.js +2 -2
- package/dist/src/generators/configuration/lib/ensure-dependencies.js +9 -0
- package/dist/src/generators/init/init.js +6 -0
- package/dist/src/migrations/update-23-0-0/migrate-jest-configuration-skip-setup-file.md +2 -2
- package/dist/src/migrations/update-23-0-0/migrate-jest-executor-setup-file.js +3 -5
- package/dist/src/migrations/update-23-0-0/migrate-jest-executor-setup-file.md +2 -2
- package/dist/src/plugins/plugin.js +6 -13
- package/migrations.json +4 -2
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JestExecutorOptions } from './schema';
|
|
2
2
|
import { Config } from '@jest/types';
|
|
3
3
|
import { ExecutorContext, TaskGraph } from '@nx/devkit';
|
|
4
|
-
import type
|
|
4
|
+
import { type BatchResults } from '@nx/devkit/internal';
|
|
5
5
|
export declare function jestExecutor(options: JestExecutorOptions, context: ExecutorContext): Promise<{
|
|
6
6
|
success: boolean;
|
|
7
7
|
}>;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createJestConfig = createJestConfig;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
|
|
6
5
|
const config_file_1 = require("../../../utils/config/config-file");
|
|
7
6
|
const internal_1 = require("@nx/js/internal");
|
|
7
|
+
const internal_2 = require("@nx/devkit/internal");
|
|
8
8
|
async function createJestConfig(tree, options, presetExt) {
|
|
9
9
|
if (!tree.exists(`jest.preset.${presetExt}`)) {
|
|
10
10
|
if (presetExt === 'mjs') {
|
|
@@ -63,7 +63,7 @@ module.exports = { ...nxPreset };`);
|
|
|
63
63
|
: 'lib'}.${options.js ? 'js' : 'ts'}`;
|
|
64
64
|
tree.rename(rootJestPath, jestProjectConfig);
|
|
65
65
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
66
|
-
const targetDefaults = (0,
|
|
66
|
+
const targetDefaults = (0, internal_2.readTargetDefaultsForTarget)(jestTargetName, nxJson.targetDefaults, jestTargetConfigInGraph.executor);
|
|
67
67
|
const target = (rootProjectConfig.targets[jestTargetName] ??=
|
|
68
68
|
jestTargetConfigInGraph.executor === 'nx:run-commands'
|
|
69
69
|
? { command: `jest --config ${jestProjectConfig}` }
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureDependencies = ensureDependencies;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
6
|
+
const internal_2 = require("@nx/js/internal");
|
|
5
7
|
const versions_1 = require("../../../utils/versions");
|
|
6
8
|
function ensureDependencies(tree, options) {
|
|
7
9
|
const { babelJestVersion, jestTypesVersion, jestVersion, nxVersion, swcJestVersion, tsJestVersion, tslibVersion, tsNodeVersion, typesNodeVersion, } = (0, versions_1.versions)(tree);
|
|
@@ -31,6 +33,13 @@ function ensureDependencies(tree, options) {
|
|
|
31
33
|
}
|
|
32
34
|
else if (options.compiler === 'swc') {
|
|
33
35
|
devDeps['@swc/jest'] = swcJestVersion;
|
|
36
|
+
// peer dependency of @swc/jest
|
|
37
|
+
devDeps['@swc/core'] = internal_2.swcCoreVersion;
|
|
38
|
+
// @swc/core's postinstall only installs a wasm fallback for platforms not
|
|
39
|
+
// covered by its prebuilt optional dependencies, so skip it.
|
|
40
|
+
(0, internal_1.acknowledgeBuildScripts)(tree, (0, devkit_1.detectPackageManager)(tree.root), {
|
|
41
|
+
'@swc/core': false,
|
|
42
|
+
});
|
|
34
43
|
}
|
|
35
44
|
return (0, devkit_1.addDependenciesToPackageJson)(tree, dependencies, devDeps, undefined, options.keepExistingVersions ?? true);
|
|
36
45
|
}
|
|
@@ -70,6 +70,12 @@ function createJestDefaultPatch(existing, productionFileSet, presetExt) {
|
|
|
70
70
|
}
|
|
71
71
|
function updateDependencies(tree, options) {
|
|
72
72
|
const { jestVersion, nxVersion } = (0, versions_1.versions)(tree);
|
|
73
|
+
// jest 30 pulls in unrs-resolver; its postinstall only fetches a fallback
|
|
74
|
+
// binding for platforms not covered by its prebuilt optional dependencies,
|
|
75
|
+
// so skip it.
|
|
76
|
+
(0, internal_1.acknowledgeBuildScripts)(tree, (0, devkit_1.detectPackageManager)(tree.root), {
|
|
77
|
+
'unrs-resolver': false,
|
|
78
|
+
});
|
|
73
79
|
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
74
80
|
'@nx/jest': nxVersion,
|
|
75
81
|
jest: jestVersion,
|
|
@@ -5,7 +5,7 @@ Migrates the previously deprecated `skipSetupFile` option of the `@nx/jest:confi
|
|
|
5
5
|
- `skipSetupFile: true` becomes `setupFile: 'none'` (preserving the original behavior of skipping the setup file). Existing `setupFile` values are left untouched.
|
|
6
6
|
- `skipSetupFile: false` is dropped (it was a no-op).
|
|
7
7
|
|
|
8
|
-
Both flat (`@nx/jest:configuration`) and nested (`@nx/jest`
|
|
8
|
+
Both flat (`@nx/jest:configuration`) and nested (`@nx/jest` -> `configuration`) forms are handled.
|
|
9
9
|
|
|
10
10
|
#### Examples
|
|
11
11
|
|
|
@@ -88,4 +88,4 @@ Rewrite a per-project generator default:
|
|
|
88
88
|
}
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
The nested form (`@nx/jest`
|
|
91
|
+
The nested form (`@nx/jest` -> `configuration`) is handled the same way.
|
|
@@ -4,8 +4,6 @@ exports.default = default_1;
|
|
|
4
4
|
const internal_1 = require("@nx/devkit/internal");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const internal_2 = require("@nx/js/internal");
|
|
7
|
-
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
8
|
-
const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
|
|
9
7
|
const path_1 = require("path");
|
|
10
8
|
const functions_1 = require("../../utils/config/functions");
|
|
11
9
|
const EXECUTOR_TO_MIGRATE = '@nx/jest:jest';
|
|
@@ -168,7 +166,7 @@ function migrateOneJestConfig(tree, jestConfigPath, setupFile, location, rewritt
|
|
|
168
166
|
function migrateInheritedSetupFile(tree, project, target, nxJson, projectConfigCache, rewrittenJestConfigs, warnLists) {
|
|
169
167
|
if (!nxJson?.targetDefaults)
|
|
170
168
|
return;
|
|
171
|
-
const matched = (0,
|
|
169
|
+
const matched = (0, internal_1.readTargetDefaultsForTarget)(target, nxJson.targetDefaults, EXECUTOR_TO_MIGRATE);
|
|
172
170
|
const inheritedSetupFile = matched?.options?.[SETUP_FILE];
|
|
173
171
|
if (inheritedSetupFile === undefined)
|
|
174
172
|
return;
|
|
@@ -308,14 +306,14 @@ function resolveJestConfigPath(callbackJestConfig, targetJestConfig, projectRoot
|
|
|
308
306
|
return expandWorkspaceRelativePath(explicit, projectRoot);
|
|
309
307
|
if (!nxJson?.targetDefaults)
|
|
310
308
|
return undefined;
|
|
311
|
-
const matched = (0,
|
|
309
|
+
const matched = (0, internal_1.readTargetDefaultsForTarget)(target, nxJson.targetDefaults, EXECUTOR_TO_MIGRATE);
|
|
312
310
|
const fromDefaults = matched?.options?.[JEST_CONFIG];
|
|
313
311
|
if (fromDefaults)
|
|
314
312
|
return expandWorkspaceRelativePath(fromDefaults, projectRoot);
|
|
315
313
|
return undefined;
|
|
316
314
|
}
|
|
317
315
|
function expandWorkspaceRelativePath(value, projectRoot) {
|
|
318
|
-
return path_1.posix.normalize((0,
|
|
316
|
+
return path_1.posix.normalize((0, internal_1.interpolate)(value, {
|
|
319
317
|
projectRoot: projectRoot || '.',
|
|
320
318
|
workspaceRoot: '.',
|
|
321
319
|
}));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Migrates the previously deprecated `setupFile` option of the `@nx/jest:jest` executor. The setup file path is appended to the `setupFilesAfterEnv` array in the project's Jest configuration (using `<rootDir>/...` form), and the deprecated option is removed from `project.json` and `nx.json` target defaults.
|
|
4
4
|
|
|
5
|
-
If the
|
|
5
|
+
If the setup file cannot be migrated automatically (e.g. the Jest configuration cannot be parsed because it exports a factory function or assigns `setupFilesAfterEnv` to a non-array value, it sets `rootDir` to a non-literal value, or the target shares a Jest configuration with another target using a different setup file), the deprecated option is still removed and a warning is logged listing the affected targets so the setup file path can be moved manually.
|
|
6
6
|
|
|
7
7
|
#### Examples
|
|
8
8
|
|
|
@@ -135,7 +135,7 @@ Remove the option from a target default using the `@nx/jest:jest` executor:
|
|
|
135
135
|
}
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
Per-project paths don't make sense as workspace defaults, so the option is removed
|
|
138
|
+
Per-project paths don't make sense as workspace defaults, so the option is removed from `nx.json`. Base targets that inherited it don't lose their setup file: the inherited path is expanded and added to `setupFilesAfterEnv` in each project's Jest config, the same as if the target had declared the option itself. A warning is logged noting the removal from `nx.json`.
|
|
139
139
|
|
|
140
140
|
Remove the option from a target default entry matching on the `@nx/jest:jest` executor:
|
|
141
141
|
|
|
@@ -6,13 +6,6 @@ const devkit_1 = require("@nx/devkit");
|
|
|
6
6
|
const minimatch_1 = require("minimatch");
|
|
7
7
|
const node_fs_1 = require("node:fs");
|
|
8
8
|
const node_path_1 = require("node:path");
|
|
9
|
-
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
10
|
-
const package_json_1 = require("nx/src/plugins/package-json");
|
|
11
|
-
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
12
|
-
const globs_1 = require("nx/src/utils/globs");
|
|
13
|
-
const installation_directory_1 = require("nx/src/utils/installation-directory");
|
|
14
|
-
const plugins_1 = require("nx/src/utils/plugins");
|
|
15
|
-
const workspace_context_1 = require("nx/src/utils/workspace-context");
|
|
16
9
|
const js_1 = require("@nx/js");
|
|
17
10
|
const internal_2 = require("@nx/js/internal");
|
|
18
11
|
const versions_1 = require("../utils/versions");
|
|
@@ -21,8 +14,8 @@ const jestConfigGlob = '**/jest.config.{cjs,mjs,js,cts,mts,ts}';
|
|
|
21
14
|
exports.createNodes = [
|
|
22
15
|
jestConfigGlob,
|
|
23
16
|
async (configFiles, options, context) => {
|
|
24
|
-
const optionsHash = (0,
|
|
25
|
-
const cachePath = (0, node_path_1.join)(
|
|
17
|
+
const optionsHash = (0, internal_1.hashObject)(options);
|
|
18
|
+
const cachePath = (0, node_path_1.join)(internal_1.workspaceDataDirectory, `jest-${optionsHash}.hash`);
|
|
26
19
|
const targetsCache = new internal_1.PluginCache(cachePath);
|
|
27
20
|
// Cache jest preset(s) to avoid penalties of module load times. Most of jest configs will use the same preset.
|
|
28
21
|
const presetCache = {};
|
|
@@ -111,7 +104,7 @@ function buildPackageJsonWorkspacesMatcher(workspaceRoot) {
|
|
|
111
104
|
if (process.env.NX_INFER_ALL_PACKAGE_JSONS === 'true') {
|
|
112
105
|
return () => true;
|
|
113
106
|
}
|
|
114
|
-
const packageManagerWorkspacesGlob = (0,
|
|
107
|
+
const packageManagerWorkspacesGlob = (0, internal_1.combineGlobPatterns)((0, internal_1.getGlobPatternsFromPackageManagerWorkspaces)(workspaceRoot));
|
|
115
108
|
return (path) => (0, minimatch_1.minimatch)(path, packageManagerWorkspacesGlob);
|
|
116
109
|
}
|
|
117
110
|
function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, isInPackageManagerWorkspaces, context) {
|
|
@@ -181,7 +174,7 @@ async function buildJestTargets(rawConfig, needsDtsInputs, configFilePath, proje
|
|
|
181
174
|
const cache = (target.cache = true);
|
|
182
175
|
const inputs = (target.inputs = await getInputs(namedInputs, rawConfig, rootDir, projectRoot, context.workspaceRoot, presetCache, needsDtsInputs, useJestResolver));
|
|
183
176
|
let metadata;
|
|
184
|
-
const groupName = options?.ciGroupName ?? (0,
|
|
177
|
+
const groupName = options?.ciGroupName ?? (0, internal_1.deriveGroupNameFromTarget)(options?.ciTargetName);
|
|
185
178
|
if (disableJestRuntime) {
|
|
186
179
|
const outputs = (target.outputs = getOutputs(projectRoot, rawConfig.coverageDirectory
|
|
187
180
|
? (0, node_path_1.join)(context.workspaceRoot, projectRoot, rawConfig.coverageDirectory)
|
|
@@ -567,7 +560,7 @@ function resolveJestPath(projectRoot, workspaceRoot) {
|
|
|
567
560
|
return resolvedJestPaths[projectRoot];
|
|
568
561
|
}
|
|
569
562
|
resolvedJestPaths[projectRoot] = require.resolve('jest', {
|
|
570
|
-
paths: [projectRoot, ...(0,
|
|
563
|
+
paths: [projectRoot, ...(0, internal_1.getNxRequirePaths)(workspaceRoot), __dirname],
|
|
571
564
|
});
|
|
572
565
|
return resolvedJestPaths[projectRoot];
|
|
573
566
|
}
|
|
@@ -590,7 +583,7 @@ function requireJestUtil(packageName, projectRoot, workspaceRoot) {
|
|
|
590
583
|
}
|
|
591
584
|
async function getTestPaths(projectRoot, rawConfig, rootDir, context, presetCache) {
|
|
592
585
|
const testMatch = await getJestOption(rawConfig, rootDir, 'testMatch', presetCache);
|
|
593
|
-
let paths = await (0,
|
|
586
|
+
let paths = await (0, internal_1.globWithWorkspaceContext)(context.workspaceRoot, (testMatch || [
|
|
594
587
|
// Default copied from https://github.com/jestjs/jest/blob/d1a2ed7/packages/jest-config/src/Defaults.ts#L84
|
|
595
588
|
'**/__tests__/**/*.?([mc])[jt]s?(x)',
|
|
596
589
|
'**/?(*.)+(spec|test).?([mc])[jt]s?(x)',
|
package/migrations.json
CHANGED
|
@@ -65,12 +65,14 @@
|
|
|
65
65
|
"migrate-jest-executor-setup-file": {
|
|
66
66
|
"version": "23.0.0-beta.22",
|
|
67
67
|
"description": "Migrate the deprecated `setupFile` option of the `@nx/jest:jest` executor: push the file path into `setupFilesAfterEnv` in the project's Jest config and remove the option from `project.json` and `nx.json` target defaults.",
|
|
68
|
-
"implementation": "./dist/src/migrations/update-23-0-0/migrate-jest-executor-setup-file"
|
|
68
|
+
"implementation": "./dist/src/migrations/update-23-0-0/migrate-jest-executor-setup-file",
|
|
69
|
+
"documentation": "./dist/src/migrations/update-23-0-0/migrate-jest-executor-setup-file.md"
|
|
69
70
|
},
|
|
70
71
|
"migrate-jest-configuration-skip-setup-file": {
|
|
71
72
|
"version": "23.0.0-beta.22",
|
|
72
73
|
"description": "Migrate the deprecated `skipSetupFile` option of the `@nx/jest:configuration` generator stored as a default in `nx.json` or per-project `project.json` to `setupFile: 'none'` (when `true`) or remove it (when `false`).",
|
|
73
|
-
"implementation": "./dist/src/migrations/update-23-0-0/migrate-jest-configuration-skip-setup-file"
|
|
74
|
+
"implementation": "./dist/src/migrations/update-23-0-0/migrate-jest-configuration-skip-setup-file",
|
|
75
|
+
"documentation": "./dist/src/migrations/update-23-0-0/migrate-jest-configuration-skip-setup-file.md"
|
|
74
76
|
},
|
|
75
77
|
"update-23-0-0-migrate-create-nodes-v2-import": {
|
|
76
78
|
"version": "23.0.0-beta.24",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "23.1.
|
|
3
|
+
"version": "23.1.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -117,11 +117,11 @@
|
|
|
117
117
|
"semver": "^7.6.3",
|
|
118
118
|
"tslib": "^2.3.0",
|
|
119
119
|
"yargs-parser": "21.1.1",
|
|
120
|
-
"@nx/devkit": "23.1.
|
|
121
|
-
"@nx/js": "23.1.
|
|
120
|
+
"@nx/devkit": "23.1.2",
|
|
121
|
+
"@nx/js": "23.1.2"
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
|
-
"nx": "23.1.
|
|
124
|
+
"nx": "23.1.2"
|
|
125
125
|
},
|
|
126
126
|
"publishConfig": {
|
|
127
127
|
"access": "public"
|