@nx/jest 23.0.0-rc.3 → 23.0.0
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/generators/configuration/configuration.js +8 -20
- package/dist/src/generators/init/init.js +19 -58
- package/dist/src/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor.js +15 -47
- package/dist/src/migrations/update-21-3-0/rename-test-path-pattern.js +9 -25
- package/package.json +4 -4
|
@@ -3,9 +3,8 @@ 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");
|
|
7
6
|
const js_1 = require("@nx/js");
|
|
8
|
-
const
|
|
7
|
+
const internal_1 = require("@nx/js/internal");
|
|
9
8
|
const config_file_1 = require("../../utils/config/config-file");
|
|
10
9
|
const init_1 = require("../init/init");
|
|
11
10
|
const assert_supported_jest_version_1 = require("../../utils/assert-supported-jest-version");
|
|
@@ -48,7 +47,7 @@ function normalizeOptions(tree, options) {
|
|
|
48
47
|
...options,
|
|
49
48
|
keepExistingVersions: options.keepExistingVersions ?? true,
|
|
50
49
|
rootProject: project.root === '.' || project.root === '',
|
|
51
|
-
isTsSolutionSetup: (0,
|
|
50
|
+
isTsSolutionSetup: (0, internal_1.isUsingTsSolutionSetup)(tree),
|
|
52
51
|
};
|
|
53
52
|
}
|
|
54
53
|
function configurationGenerator(tree, schema) {
|
|
@@ -94,13 +93,12 @@ async function configurationGeneratorInternal(tree, schema) {
|
|
|
94
93
|
ignoreTestOutput(tree);
|
|
95
94
|
// in the TS solution setup, the test target depends on the build outputs
|
|
96
95
|
// so we need to setup the task pipeline accordingly
|
|
97
|
-
const nxJson = (0, devkit_1.readNxJson)(tree)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
96
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
97
|
+
nxJson.targetDefaults ??= {};
|
|
98
|
+
nxJson.targetDefaults[options.targetName] ??= {};
|
|
99
|
+
nxJson.targetDefaults[options.targetName].dependsOn ??= [];
|
|
100
|
+
nxJson.targetDefaults[options.targetName].dependsOn.push('^build');
|
|
101
|
+
nxJson.targetDefaults[options.targetName].dependsOn = Array.from(new Set(nxJson.targetDefaults[options.targetName].dependsOn));
|
|
104
102
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
105
103
|
}
|
|
106
104
|
if (!schema.skipFormat) {
|
|
@@ -108,16 +106,6 @@ async function configurationGeneratorInternal(tree, schema) {
|
|
|
108
106
|
}
|
|
109
107
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
110
108
|
}
|
|
111
|
-
function findExistingTestDefault(td, targetName) {
|
|
112
|
-
if (!td)
|
|
113
|
-
return undefined;
|
|
114
|
-
if (Array.isArray(td)) {
|
|
115
|
-
return td.find((e) => e.target === targetName &&
|
|
116
|
-
e.projects === undefined &&
|
|
117
|
-
e.plugin === undefined);
|
|
118
|
-
}
|
|
119
|
-
return td[targetName];
|
|
120
|
-
}
|
|
121
109
|
function ignoreTestOutput(tree) {
|
|
122
110
|
if (!tree.exists('.gitignore')) {
|
|
123
111
|
devkit_1.logger.warn(`Couldn't find a root .gitignore file to update.`);
|
|
@@ -29,66 +29,27 @@ function updateProductionFileSet(tree) {
|
|
|
29
29
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
30
30
|
}
|
|
31
31
|
function addJestTargetDefaults(tree, presetExt) {
|
|
32
|
-
const nxJson = (0, devkit_1.readNxJson)(tree)
|
|
32
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
33
|
+
nxJson.targetDefaults ??= {};
|
|
34
|
+
nxJson.targetDefaults['@nx/jest:jest'] ??= {};
|
|
33
35
|
const productionFileSet = nxJson.namedInputs?.production;
|
|
34
|
-
|
|
35
|
-
if (existingEntries.length === 0) {
|
|
36
|
-
const patch = createJestDefaultPatch(undefined, productionFileSet, presetExt);
|
|
37
|
-
if (Object.keys(patch).length > 0) {
|
|
38
|
-
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
39
|
-
executor: '@nx/jest:jest',
|
|
40
|
-
...patch,
|
|
41
|
-
});
|
|
42
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
43
|
-
}
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
let didUpdate = false;
|
|
47
|
-
for (const existing of existingEntries) {
|
|
48
|
-
const patch = createJestDefaultPatch(existing, productionFileSet, presetExt);
|
|
49
|
-
if (Object.keys(patch).length === 0) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
53
|
-
target: existing.target,
|
|
54
|
-
executor: existing.executor,
|
|
55
|
-
projects: existing.projects,
|
|
56
|
-
plugin: existing.plugin,
|
|
57
|
-
...patch,
|
|
58
|
-
});
|
|
59
|
-
didUpdate = true;
|
|
60
|
-
}
|
|
61
|
-
if (didUpdate) {
|
|
62
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function createJestDefaultPatch(existing, productionFileSet, presetExt) {
|
|
66
|
-
const patch = {};
|
|
67
|
-
if (existing?.cache === undefined)
|
|
68
|
-
patch.cache = true;
|
|
36
|
+
nxJson.targetDefaults['@nx/jest:jest'].cache ??= true;
|
|
69
37
|
// Test targets depend on all their project's sources + production sources of dependencies
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return patch;
|
|
89
|
-
}
|
|
90
|
-
function findExistingJestDefaults(td) {
|
|
91
|
-
return (0, internal_1.normalizeTargetDefaults)(td).filter((e) => e.executor === '@nx/jest:jest');
|
|
38
|
+
nxJson.targetDefaults['@nx/jest:jest'].inputs ??= [
|
|
39
|
+
'default',
|
|
40
|
+
productionFileSet ? '^production' : '^default',
|
|
41
|
+
`{workspaceRoot}/jest.preset.${presetExt}`,
|
|
42
|
+
];
|
|
43
|
+
nxJson.targetDefaults['@nx/jest:jest'].options ??= {
|
|
44
|
+
passWithNoTests: true,
|
|
45
|
+
};
|
|
46
|
+
nxJson.targetDefaults['@nx/jest:jest'].configurations ??= {
|
|
47
|
+
ci: {
|
|
48
|
+
ci: true,
|
|
49
|
+
codeCoverage: true,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
92
53
|
}
|
|
93
54
|
function updateDependencies(tree, options) {
|
|
94
55
|
const { jestVersion, nxVersion } = (0, versions_1.versions)(tree);
|
|
@@ -4,7 +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 EXECUTOR_TO_MIGRATE = '@nx/jest:jest';
|
|
7
|
-
const ENTRY_META_KEYS = new Set(['target', 'executor', 'projects', 'plugin']);
|
|
8
7
|
async function default_1(tree) {
|
|
9
8
|
// update options from project configs
|
|
10
9
|
(0, internal_1.forEachExecutorOptions)(tree, EXECUTOR_TO_MIGRATE, (options, project, target, configuration) => {
|
|
@@ -23,61 +22,30 @@ async function default_1(tree) {
|
|
|
23
22
|
// update options from nx.json target defaults
|
|
24
23
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
25
24
|
if (nxJson.targetDefaults) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
}
|
|
25
|
+
for (const [targetOrExecutor, targetConfig] of Object.entries(nxJson.targetDefaults)) {
|
|
26
|
+
if (targetOrExecutor !== EXECUTOR_TO_MIGRATE &&
|
|
27
|
+
targetConfig.executor !== EXECUTOR_TO_MIGRATE) {
|
|
28
|
+
continue;
|
|
42
29
|
}
|
|
43
|
-
if (
|
|
44
|
-
|
|
30
|
+
if (targetConfig.options) {
|
|
31
|
+
updateOptions(targetConfig);
|
|
45
32
|
}
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
Object.keys(targetConfig.configurations ?? {}).forEach((config) => {
|
|
34
|
+
updateConfiguration(targetConfig, config);
|
|
35
|
+
});
|
|
36
|
+
if (!Object.keys(targetConfig).length ||
|
|
37
|
+
(Object.keys(targetConfig).length === 1 &&
|
|
38
|
+
Object.keys(targetConfig)[0] === 'executor')) {
|
|
39
|
+
delete nxJson.targetDefaults[targetOrExecutor];
|
|
48
40
|
}
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
}
|
|
41
|
+
if (!Object.keys(nxJson.targetDefaults).length) {
|
|
42
|
+
delete nxJson.targetDefaults;
|
|
70
43
|
}
|
|
71
44
|
}
|
|
72
45
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
73
46
|
}
|
|
74
47
|
await (0, devkit_1.formatFiles)(tree);
|
|
75
48
|
}
|
|
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
|
-
}
|
|
81
49
|
function updateOptions(target) {
|
|
82
50
|
delete target.options.tsConfig;
|
|
83
51
|
if (!Object.keys(target.options).length) {
|
|
@@ -19,33 +19,17 @@ async function default_1(tree) {
|
|
|
19
19
|
if (!nxJson.targetDefaults) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
if (entry.options) {
|
|
29
|
-
renameTestPathPattern(entry.options);
|
|
30
|
-
}
|
|
31
|
-
Object.values(entry.configurations ?? {}).forEach((config) => {
|
|
32
|
-
renameTestPathPattern(config);
|
|
33
|
-
});
|
|
22
|
+
for (const [targetOrExecutor, targetConfig] of Object.entries(nxJson.targetDefaults)) {
|
|
23
|
+
if (targetOrExecutor !== '@nx/jest:jest' &&
|
|
24
|
+
targetConfig.executor !== '@nx/jest:jest') {
|
|
25
|
+
continue;
|
|
34
26
|
}
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
});
|
|
27
|
+
if (targetConfig.options) {
|
|
28
|
+
renameTestPathPattern(targetConfig.options);
|
|
48
29
|
}
|
|
30
|
+
Object.values(targetConfig.configurations ?? {}).forEach((config) => {
|
|
31
|
+
renameTestPathPattern(config);
|
|
32
|
+
});
|
|
49
33
|
}
|
|
50
34
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
51
35
|
await (0, devkit_1.formatFiles)(tree);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "23.0.0
|
|
3
|
+
"version": "23.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -116,11 +116,11 @@
|
|
|
116
116
|
"semver": "^7.6.3",
|
|
117
117
|
"tslib": "^2.3.0",
|
|
118
118
|
"yargs-parser": "21.1.1",
|
|
119
|
-
"@nx/devkit": "23.0.0
|
|
120
|
-
"@nx/js": "23.0.0
|
|
119
|
+
"@nx/devkit": "23.0.0",
|
|
120
|
+
"@nx/js": "23.0.0"
|
|
121
121
|
},
|
|
122
122
|
"devDependencies": {
|
|
123
|
-
"nx": "23.0.0
|
|
123
|
+
"nx": "23.0.0"
|
|
124
124
|
},
|
|
125
125
|
"publishConfig": {
|
|
126
126
|
"access": "public"
|