@nx/jest 23.0.0-beta.12 → 23.0.0-beta.13
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/package.json +4 -4
- package/plugins/resolver.js +1 -1
- package/src/generators/configuration/configuration.d.ts.map +1 -1
- package/src/generators/configuration/configuration.js +20 -8
- package/src/generators/configuration/lib/create-files.js +2 -2
- package/src/generators/configuration/lib/create-jest-config.js +2 -2
- package/src/generators/configuration/lib/update-tsconfig.js +2 -2
- package/src/generators/init/init.d.ts.map +1 -1
- package/src/generators/init/init.js +58 -19
- package/src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync.js +2 -2
- package/src/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.d.ts.map +1 -1
- package/src/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.js +47 -15
- package/src/migrations/update-21-0-0/replace-getJestProjects-with-getJestProjectsAsync.js +2 -2
- package/src/migrations/update-21-3-0/rename-test-path-pattern.d.ts.map +1 -1
- package/src/migrations/update-21-3-0/rename-test-path-pattern.js +25 -9
- package/src/plugins/plugin.js +5 -2
- package/src/utils/config/functions.js +7 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "23.0.0-beta.
|
|
3
|
+
"version": "23.0.0-beta.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Jest contains executors and generators allowing your workspace to use the powerful Jest testing capabilities.",
|
|
6
6
|
"repository": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@jest/reporters": "^30.0.2",
|
|
40
40
|
"@jest/test-result": "^30.0.2",
|
|
41
|
-
"@nx/devkit": "23.0.0-beta.
|
|
42
|
-
"@nx/js": "23.0.0-beta.
|
|
41
|
+
"@nx/devkit": "23.0.0-beta.13",
|
|
42
|
+
"@nx/js": "23.0.0-beta.13",
|
|
43
43
|
"@phenomnomnominal/tsquery": "~6.2.0",
|
|
44
44
|
"identity-obj-proxy": "3.0.0",
|
|
45
45
|
"jest-config": "^30.0.2",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"yargs-parser": "21.1.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"nx": "23.0.0-beta.
|
|
56
|
+
"nx": "23.0.0-beta.13"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
package/plugins/resolver.js
CHANGED
|
@@ -19,7 +19,7 @@ function getCompilerSetup(rootDir) {
|
|
|
19
19
|
const config = ts.parseJsonConfigFileContent(readResult.config, ts.sys, (0, path_1.dirname)(tsConfigPath));
|
|
20
20
|
const compilerOptions = config.options;
|
|
21
21
|
if (!compilerOptions.baseUrl) {
|
|
22
|
-
const { resolvePathsBaseUrl
|
|
22
|
+
const { resolvePathsBaseUrl } = require('@nx/js');
|
|
23
23
|
compilerOptions.baseUrl = resolvePathsBaseUrl(tsConfigPath);
|
|
24
24
|
}
|
|
25
25
|
const host = ts.createCompilerHost(compilerOptions, true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/generators/configuration/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/generators/configuration/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAOjB,IAAI,EAEL,MAAM,YAAY,CAAC;AAkBpB,OAAO,EAAE,iBAAiB,EAA+B,MAAM,UAAU,CAAC;AAyD1E,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,iBAAiB,8BAE3E;AAED,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,iBAAiB,CAAC,CAsE5B;AAgCD,eAAe,sBAAsB,CAAC"}
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.configurationGenerator = configurationGenerator;
|
|
4
4
|
exports.configurationGeneratorInternal = configurationGeneratorInternal;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
6
7
|
const js_1 = require("@nx/js");
|
|
7
|
-
const
|
|
8
|
+
const internal_2 = require("@nx/js/internal");
|
|
8
9
|
const config_file_1 = require("../../utils/config/config-file");
|
|
9
10
|
const init_1 = require("../init/init");
|
|
10
11
|
const deprecation_1 = require("../../utils/deprecation");
|
|
@@ -51,7 +52,7 @@ function normalizeOptions(tree, options) {
|
|
|
51
52
|
...options,
|
|
52
53
|
keepExistingVersions: options.keepExistingVersions ?? true,
|
|
53
54
|
rootProject: project.root === '.' || project.root === '',
|
|
54
|
-
isTsSolutionSetup: (0,
|
|
55
|
+
isTsSolutionSetup: (0, internal_2.isUsingTsSolutionSetup)(tree),
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
function configurationGenerator(tree, schema) {
|
|
@@ -96,12 +97,13 @@ async function configurationGeneratorInternal(tree, schema) {
|
|
|
96
97
|
ignoreTestOutput(tree);
|
|
97
98
|
// in the TS solution setup, the test target depends on the build outputs
|
|
98
99
|
// so we need to setup the task pipeline accordingly
|
|
99
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
100
|
-
nxJson.targetDefaults
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
|
|
101
|
+
const existing = findExistingTestDefault(nxJson.targetDefaults, options.targetName);
|
|
102
|
+
const dependsOn = Array.from(new Set([...(existing?.dependsOn ?? []), '^build']));
|
|
103
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
104
|
+
target: options.targetName,
|
|
105
|
+
dependsOn,
|
|
106
|
+
});
|
|
105
107
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
106
108
|
}
|
|
107
109
|
if (!schema.skipFormat) {
|
|
@@ -109,6 +111,16 @@ async function configurationGeneratorInternal(tree, schema) {
|
|
|
109
111
|
}
|
|
110
112
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
111
113
|
}
|
|
114
|
+
function findExistingTestDefault(td, targetName) {
|
|
115
|
+
if (!td)
|
|
116
|
+
return undefined;
|
|
117
|
+
if (Array.isArray(td)) {
|
|
118
|
+
return td.find((e) => e.target === targetName &&
|
|
119
|
+
e.projects === undefined &&
|
|
120
|
+
e.plugin === undefined);
|
|
121
|
+
}
|
|
122
|
+
return td[targetName];
|
|
123
|
+
}
|
|
112
124
|
function ignoreTestOutput(tree) {
|
|
113
125
|
if (!tree.exists('.gitignore')) {
|
|
114
126
|
devkit_1.logger.warn(`Couldn't find a root .gitignore file to update.`);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createFiles = createFiles;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
5
|
+
const internal_1 = require("@nx/js/internal");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const versions_1 = require("../../../utils/versions");
|
|
8
8
|
function createFiles(tree, options, presetExt) {
|
|
@@ -33,7 +33,7 @@ function createFiles(tree, options, presetExt) {
|
|
|
33
33
|
transformerOptions = "{ tsconfig: '<rootDir>/tsconfig.spec.json' }";
|
|
34
34
|
}
|
|
35
35
|
if (options.compiler === 'swc' && options.isTsSolutionSetup) {
|
|
36
|
-
(0,
|
|
36
|
+
(0, internal_1.addSwcTestConfig)(tree, projectConfig.root, 'es6', options.supportTsx);
|
|
37
37
|
}
|
|
38
38
|
const projectRoot = options.rootProject
|
|
39
39
|
? options.project
|
|
@@ -4,7 +4,7 @@ exports.createJestConfig = createJestConfig;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
|
|
6
6
|
const config_file_1 = require("../../../utils/config/config-file");
|
|
7
|
-
const
|
|
7
|
+
const internal_1 = require("@nx/js/internal");
|
|
8
8
|
async function createJestConfig(tree, options, presetExt) {
|
|
9
9
|
if (!tree.exists(`jest.preset.${presetExt}`)) {
|
|
10
10
|
if (presetExt === 'mjs') {
|
|
@@ -58,7 +58,7 @@ module.exports = { ...nxPreset };`);
|
|
|
58
58
|
// Jest target has already been updated
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
const jestProjectConfig = `jest.config.${(0,
|
|
61
|
+
const jestProjectConfig = `jest.config.${(0, internal_1.getProjectType)(tree, rootProjectConfig.root, rootProjectConfig.projectType) === 'application'
|
|
62
62
|
? 'app'
|
|
63
63
|
: 'lib'}.${options.js ? 'js' : 'ts'}`;
|
|
64
64
|
tree.rename(rootJestPath, jestProjectConfig);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateTsConfig = updateTsConfig;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
5
|
+
const internal_1 = require("@nx/js/internal");
|
|
6
6
|
function updateTsConfig(host, options) {
|
|
7
7
|
const { root, projectType: _projectType } = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
8
8
|
if (!host.exists((0, devkit_1.joinPathFragments)(root, 'tsconfig.json'))) {
|
|
@@ -25,7 +25,7 @@ function updateTsConfig(host, options) {
|
|
|
25
25
|
}
|
|
26
26
|
return json;
|
|
27
27
|
});
|
|
28
|
-
const projectType = (0,
|
|
28
|
+
const projectType = (0, internal_1.getProjectType)(host, root, _projectType);
|
|
29
29
|
// fall-back runtime tsconfig file path in case the user didn't provide one
|
|
30
30
|
let runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(root, projectType === 'application' ? 'tsconfig.app.json' : 'tsconfig.lib.json');
|
|
31
31
|
if (options.runtimeTsconfigFileName) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/generators/init/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/generators/init/init.ts"],"names":[],"mappings":"AAKA,OAAO,EAQL,KAAK,iBAAiB,EAItB,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAWpB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AA+H/C,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,8BAEpE;AAED,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,iBAAiB,CAAC,CA2C5B;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -28,27 +28,66 @@ function updateProductionFileSet(tree) {
|
|
|
28
28
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
29
29
|
}
|
|
30
30
|
function addJestTargetDefaults(tree, presetExt) {
|
|
31
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
32
|
-
nxJson.targetDefaults ??= {};
|
|
33
|
-
nxJson.targetDefaults['@nx/jest:jest'] ??= {};
|
|
31
|
+
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
|
|
34
32
|
const productionFileSet = nxJson.namedInputs?.production;
|
|
35
|
-
nxJson.targetDefaults
|
|
33
|
+
const existingEntries = findExistingJestDefaults(nxJson.targetDefaults);
|
|
34
|
+
if (existingEntries.length === 0) {
|
|
35
|
+
const patch = createJestDefaultPatch(undefined, productionFileSet, presetExt);
|
|
36
|
+
if (Object.keys(patch).length > 0) {
|
|
37
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
38
|
+
executor: '@nx/jest:jest',
|
|
39
|
+
...patch,
|
|
40
|
+
});
|
|
41
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let didUpdate = false;
|
|
46
|
+
for (const existing of existingEntries) {
|
|
47
|
+
const patch = createJestDefaultPatch(existing, productionFileSet, presetExt);
|
|
48
|
+
if (Object.keys(patch).length === 0) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
52
|
+
target: existing.target,
|
|
53
|
+
executor: existing.executor,
|
|
54
|
+
projects: existing.projects,
|
|
55
|
+
plugin: existing.plugin,
|
|
56
|
+
...patch,
|
|
57
|
+
});
|
|
58
|
+
didUpdate = true;
|
|
59
|
+
}
|
|
60
|
+
if (didUpdate) {
|
|
61
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function createJestDefaultPatch(existing, productionFileSet, presetExt) {
|
|
65
|
+
const patch = {};
|
|
66
|
+
if (existing?.cache === undefined)
|
|
67
|
+
patch.cache = true;
|
|
36
68
|
// Test targets depend on all their project's sources + production sources of dependencies
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
if (existing?.inputs === undefined) {
|
|
70
|
+
patch.inputs = [
|
|
71
|
+
'default',
|
|
72
|
+
productionFileSet ? '^production' : '^default',
|
|
73
|
+
`{workspaceRoot}/jest.preset.${presetExt}`,
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
if (existing?.options === undefined) {
|
|
77
|
+
patch.options = { passWithNoTests: true };
|
|
78
|
+
}
|
|
79
|
+
if (existing?.configurations === undefined) {
|
|
80
|
+
patch.configurations = {
|
|
81
|
+
ci: {
|
|
82
|
+
ci: true,
|
|
83
|
+
codeCoverage: true,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return patch;
|
|
88
|
+
}
|
|
89
|
+
function findExistingJestDefaults(td) {
|
|
90
|
+
return (0, internal_1.normalizeTargetDefaults)(td).filter((e) => e.executor === '@nx/jest:jest');
|
|
52
91
|
}
|
|
53
92
|
function updateDependencies(tree, options) {
|
|
54
93
|
const { jestVersion, nxVersion } = (0, versions_1.versions)(tree);
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = update;
|
|
7
7
|
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const
|
|
8
|
+
const internal_1 = require("@nx/js/internal");
|
|
9
9
|
let tsModule;
|
|
10
10
|
async function update(tree) {
|
|
11
11
|
if (!tsModule) {
|
|
12
|
-
tsModule = (0,
|
|
12
|
+
tsModule = (0, internal_1.ensureTypescript)();
|
|
13
13
|
}
|
|
14
14
|
const jestConfigPaths = await (0, devkit_1.globAsync)(tree, [
|
|
15
15
|
'**/jest.config.{cjs,mjs,js,cts,mts,ts}',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-tsconfig-option-from-jest-executor.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"remove-tsconfig-option-from-jest-executor.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,IAAI,EAGV,MAAM,YAAY,CAAC;AAKpB,yBAA+B,IAAI,EAAE,IAAI,iBAyFxC"}
|
|
@@ -4,6 +4,7 @@ exports.default = default_1;
|
|
|
4
4
|
const internal_1 = require("@nx/devkit/internal");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const EXECUTOR_TO_MIGRATE = '@nx/jest:jest';
|
|
7
|
+
const ENTRY_META_KEYS = new Set(['target', 'executor', 'projects', 'plugin']);
|
|
7
8
|
async function default_1(tree) {
|
|
8
9
|
// update options from project configs
|
|
9
10
|
(0, internal_1.forEachExecutorOptions)(tree, EXECUTOR_TO_MIGRATE, (options, project, target, configuration) => {
|
|
@@ -22,30 +23,61 @@ async function default_1(tree) {
|
|
|
22
23
|
// update options from nx.json target defaults
|
|
23
24
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
24
25
|
if (nxJson.targetDefaults) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (Array.isArray(nxJson.targetDefaults)) {
|
|
27
|
+
const next = [];
|
|
28
|
+
for (const entry of nxJson.targetDefaults) {
|
|
29
|
+
if (entry.target !== EXECUTOR_TO_MIGRATE &&
|
|
30
|
+
entry.executor !== EXECUTOR_TO_MIGRATE) {
|
|
31
|
+
next.push(entry);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (entry.options)
|
|
35
|
+
updateOptions(entry);
|
|
36
|
+
Object.keys(entry.configurations ?? {}).forEach((config) => {
|
|
37
|
+
updateConfiguration(entry, config);
|
|
38
|
+
});
|
|
39
|
+
if (!isEntryEmpty(entry)) {
|
|
40
|
+
next.push(entry);
|
|
41
|
+
}
|
|
29
42
|
}
|
|
30
|
-
if (
|
|
31
|
-
|
|
43
|
+
if (next.length === 0) {
|
|
44
|
+
delete nxJson.targetDefaults;
|
|
32
45
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
if (!Object.keys(targetConfig).length ||
|
|
37
|
-
(Object.keys(targetConfig).length === 1 &&
|
|
38
|
-
Object.keys(targetConfig)[0] === 'executor')) {
|
|
39
|
-
delete nxJson.targetDefaults[targetOrExecutor];
|
|
46
|
+
else {
|
|
47
|
+
nxJson.targetDefaults = next;
|
|
40
48
|
}
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
for (const [targetOrExecutor, targetConfig] of Object.entries(nxJson.targetDefaults)) {
|
|
52
|
+
if (targetOrExecutor !== EXECUTOR_TO_MIGRATE &&
|
|
53
|
+
targetConfig.executor !== EXECUTOR_TO_MIGRATE) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (targetConfig.options) {
|
|
57
|
+
updateOptions(targetConfig);
|
|
58
|
+
}
|
|
59
|
+
Object.keys(targetConfig.configurations ?? {}).forEach((config) => {
|
|
60
|
+
updateConfiguration(targetConfig, config);
|
|
61
|
+
});
|
|
62
|
+
if (!Object.keys(targetConfig).length ||
|
|
63
|
+
(Object.keys(targetConfig).length === 1 &&
|
|
64
|
+
Object.keys(targetConfig)[0] === 'executor')) {
|
|
65
|
+
delete nxJson.targetDefaults[targetOrExecutor];
|
|
66
|
+
}
|
|
67
|
+
if (!Object.keys(nxJson.targetDefaults).length) {
|
|
68
|
+
delete nxJson.targetDefaults;
|
|
69
|
+
}
|
|
43
70
|
}
|
|
44
71
|
}
|
|
45
72
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
46
73
|
}
|
|
47
74
|
await (0, devkit_1.formatFiles)(tree);
|
|
48
75
|
}
|
|
76
|
+
// An entry is "empty" once only filter/meta keys remain (target, executor,
|
|
77
|
+
// projects, plugin) — nothing else worth keeping around.
|
|
78
|
+
function isEntryEmpty(entry) {
|
|
79
|
+
return Object.keys(entry).every((k) => ENTRY_META_KEYS.has(k));
|
|
80
|
+
}
|
|
49
81
|
function updateOptions(target) {
|
|
50
82
|
delete target.options.tsConfig;
|
|
51
83
|
if (!Object.keys(target.options).length) {
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = update;
|
|
7
7
|
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const
|
|
8
|
+
const internal_1 = require("@nx/js/internal");
|
|
9
9
|
let tsModule;
|
|
10
10
|
async function update(tree) {
|
|
11
11
|
if (!tsModule) {
|
|
12
|
-
tsModule = (0,
|
|
12
|
+
tsModule = (0, internal_1.ensureTypescript)();
|
|
13
13
|
}
|
|
14
14
|
const jestConfigPaths = await (0, devkit_1.globAsync)(tree, [
|
|
15
15
|
'**/jest.config.{cjs,mjs,js,cts,mts,ts}',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename-test-path-pattern.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/migrations/update-21-3-0/rename-test-path-pattern.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAIpB,yBAA+B,IAAI,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"rename-test-path-pattern.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/migrations/update-21-3-0/rename-test-path-pattern.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAIpB,yBAA+B,IAAI,EAAE,IAAI,iBAgExC"}
|
|
@@ -19,17 +19,33 @@ async function default_1(tree) {
|
|
|
19
19
|
if (!nxJson.targetDefaults) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if (Array.isArray(nxJson.targetDefaults)) {
|
|
23
|
+
for (const entry of nxJson.targetDefaults) {
|
|
24
|
+
if (entry.target !== '@nx/jest:jest' &&
|
|
25
|
+
entry.executor !== '@nx/jest:jest') {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (entry.options) {
|
|
29
|
+
renameTestPathPattern(entry.options);
|
|
30
|
+
}
|
|
31
|
+
Object.values(entry.configurations ?? {}).forEach((config) => {
|
|
32
|
+
renameTestPathPattern(config);
|
|
33
|
+
});
|
|
26
34
|
}
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
for (const [targetOrExecutor, targetConfig] of Object.entries(nxJson.targetDefaults)) {
|
|
38
|
+
if (targetOrExecutor !== '@nx/jest:jest' &&
|
|
39
|
+
targetConfig.executor !== '@nx/jest:jest') {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (targetConfig.options) {
|
|
43
|
+
renameTestPathPattern(targetConfig.options);
|
|
44
|
+
}
|
|
45
|
+
Object.values(targetConfig.configurations ?? {}).forEach((config) => {
|
|
46
|
+
renameTestPathPattern(config);
|
|
47
|
+
});
|
|
29
48
|
}
|
|
30
|
-
Object.values(targetConfig.configurations ?? {}).forEach((config) => {
|
|
31
|
-
renameTestPathPattern(config);
|
|
32
|
-
});
|
|
33
49
|
}
|
|
34
50
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
35
51
|
await (0, devkit_1.formatFiles)(tree);
|
package/src/plugins/plugin.js
CHANGED
|
@@ -14,7 +14,7 @@ const installation_directory_1 = require("nx/src/utils/installation-directory");
|
|
|
14
14
|
const plugins_1 = require("nx/src/utils/plugins");
|
|
15
15
|
const workspace_context_1 = require("nx/src/utils/workspace-context");
|
|
16
16
|
const js_1 = require("@nx/js");
|
|
17
|
-
const internal_2 = require("@nx/js/
|
|
17
|
+
const internal_2 = require("@nx/js/internal");
|
|
18
18
|
const versions_1 = require("../utils/versions");
|
|
19
19
|
const REPORTER_BUILTINS = new Set(['default', 'github-actions', 'summary']);
|
|
20
20
|
const jestConfigGlob = '**/jest.config.{cjs,mjs,js,cts,mts,ts}';
|
|
@@ -294,7 +294,10 @@ async function buildJestTargets(rawConfig, needsDtsInputs, configFilePath, proje
|
|
|
294
294
|
? await source.getTestPaths(config.globalConfig, config.projectConfig)
|
|
295
295
|
: // @ts-expect-error Jest v29 doesn't have the projectConfig parameter
|
|
296
296
|
await source.getTestPaths(config.globalConfig);
|
|
297
|
-
|
|
297
|
+
// Sort to keep atomized target name insertion order stable.
|
|
298
|
+
// jest.SearchSource.getTestPaths walks via jest-haste-map's
|
|
299
|
+
// parallel workers, so its output order isn't guaranteed.
|
|
300
|
+
const testPaths = new Set(specs.tests.map(({ path }) => path).sort());
|
|
298
301
|
if (testPaths.size > 0) {
|
|
299
302
|
const targetGroup = [];
|
|
300
303
|
metadata = {
|
|
@@ -7,14 +7,14 @@ exports.jestConfigObject = jestConfigObject;
|
|
|
7
7
|
const devkit_1 = require("@nx/devkit");
|
|
8
8
|
const vm_1 = require("vm");
|
|
9
9
|
const path_1 = require("path");
|
|
10
|
-
const
|
|
10
|
+
const internal_1 = require("@nx/js/internal");
|
|
11
11
|
let tsModule;
|
|
12
12
|
function makeTextToInsert(value, precedingCommaNeeded) {
|
|
13
13
|
return `${precedingCommaNeeded ? ',' : ''}${value}`;
|
|
14
14
|
}
|
|
15
15
|
function findPropertyAssignment(object, propertyName) {
|
|
16
16
|
if (!tsModule) {
|
|
17
|
-
tsModule = (0,
|
|
17
|
+
tsModule = (0, internal_1.ensureTypescript)();
|
|
18
18
|
}
|
|
19
19
|
return object.properties.find((prop) => {
|
|
20
20
|
if (!tsModule.isPropertyAssignment(prop)) {
|
|
@@ -29,7 +29,7 @@ function findPropertyAssignment(object, propertyName) {
|
|
|
29
29
|
}
|
|
30
30
|
function addOrUpdateProperty(tree, object, properties, value, path) {
|
|
31
31
|
if (!tsModule) {
|
|
32
|
-
tsModule = (0,
|
|
32
|
+
tsModule = (0, internal_1.ensureTypescript)();
|
|
33
33
|
}
|
|
34
34
|
const { SyntaxKind } = tsModule;
|
|
35
35
|
const propertyName = properties.shift();
|
|
@@ -109,7 +109,7 @@ function addOrUpdateProperty(tree, object, properties, value, path) {
|
|
|
109
109
|
}
|
|
110
110
|
function removeProperty(object, properties) {
|
|
111
111
|
if (!tsModule) {
|
|
112
|
-
tsModule = (0,
|
|
112
|
+
tsModule = (0, internal_1.ensureTypescript)();
|
|
113
113
|
}
|
|
114
114
|
const propertyName = properties.shift();
|
|
115
115
|
const propertyAssignment = findPropertyAssignment(object, propertyName);
|
|
@@ -127,7 +127,7 @@ function removeProperty(object, properties) {
|
|
|
127
127
|
}
|
|
128
128
|
function isModuleExport(node) {
|
|
129
129
|
if (!tsModule) {
|
|
130
|
-
tsModule = (0,
|
|
130
|
+
tsModule = (0, internal_1.ensureTypescript)();
|
|
131
131
|
}
|
|
132
132
|
return (tsModule.isExpressionStatement(node) &&
|
|
133
133
|
node.expression?.kind &&
|
|
@@ -137,7 +137,7 @@ function isModuleExport(node) {
|
|
|
137
137
|
}
|
|
138
138
|
function isDefaultExport(node) {
|
|
139
139
|
if (!tsModule) {
|
|
140
|
-
tsModule = (0,
|
|
140
|
+
tsModule = (0, internal_1.ensureTypescript)();
|
|
141
141
|
}
|
|
142
142
|
return (tsModule.isExportAssignment(node) &&
|
|
143
143
|
node.expression?.kind &&
|
|
@@ -149,7 +149,7 @@ function isDefaultExport(node) {
|
|
|
149
149
|
*/
|
|
150
150
|
function jestConfigObjectAst(fileContent) {
|
|
151
151
|
if (!tsModule) {
|
|
152
|
-
tsModule = (0,
|
|
152
|
+
tsModule = (0, internal_1.ensureTypescript)();
|
|
153
153
|
}
|
|
154
154
|
const sourceFile = tsModule.createSourceFile('jest.config.ts', fileContent, tsModule.ScriptTarget.Latest, true);
|
|
155
155
|
const exportStatement = sourceFile.statements.find((statement) => isModuleExport(statement) || isDefaultExport(statement));
|