@nx/jest 17.0.3 → 17.1.0-beta.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/migrations.json +5 -0
- package/package.json +4 -4
- package/src/generators/configuration/lib/update-workspace.js +0 -7
- package/src/generators/init/init.js +22 -6
- package/src/migrations/update-17-1-0/move-options-to-target-defaults.d.ts +2 -0
- package/src/migrations/update-17-1-0/move-options-to-target-defaults.js +117 -0
package/migrations.json
CHANGED
|
@@ -29,6 +29,11 @@
|
|
|
29
29
|
"version": "16.5.0-beta.2",
|
|
30
30
|
"description": "Add test-setup.ts to ignored files in production input",
|
|
31
31
|
"implementation": "./src/migrations/update-16-5-0/add-test-setup-to-inputs-ignore"
|
|
32
|
+
},
|
|
33
|
+
"move-options-to-target-defaults": {
|
|
34
|
+
"version": "17.1.0-beta.2",
|
|
35
|
+
"description": "Move jest executor options to nx.json targetDefaults",
|
|
36
|
+
"implementation": "./src/migrations/update-17-1-0/move-options-to-target-defaults"
|
|
32
37
|
}
|
|
33
38
|
},
|
|
34
39
|
"packageJsonUpdates": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.1.0-beta.2",
|
|
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": {
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"jest-util": "^29.4.1",
|
|
45
45
|
"resolve.exports": "1.1.0",
|
|
46
46
|
"tslib": "^2.3.0",
|
|
47
|
-
"@nx/devkit": "17.0.
|
|
48
|
-
"@nx/js": "17.0.
|
|
49
|
-
"@nrwl/jest": "17.0.
|
|
47
|
+
"@nx/devkit": "17.1.0-beta.2",
|
|
48
|
+
"@nx/js": "17.1.0-beta.2",
|
|
49
|
+
"@nrwl/jest": "17.1.0-beta.2"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
@@ -16,13 +16,6 @@ function updateWorkspace(tree, options) {
|
|
|
16
16
|
],
|
|
17
17
|
options: {
|
|
18
18
|
jestConfig: (0, devkit_1.joinPathFragments)((0, devkit_1.normalizePath)(projectConfig.root), `jest.config.${options.js ? 'js' : 'ts'}`),
|
|
19
|
-
passWithNoTests: true,
|
|
20
|
-
},
|
|
21
|
-
configurations: {
|
|
22
|
-
ci: {
|
|
23
|
-
ci: true,
|
|
24
|
-
codeCoverage: true,
|
|
25
|
-
},
|
|
26
19
|
},
|
|
27
20
|
};
|
|
28
21
|
(0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
|
|
@@ -34,7 +34,8 @@ function createJestConfig(tree, options) {
|
|
|
34
34
|
const nxPreset = require('@nx/jest/preset').default;
|
|
35
35
|
|
|
36
36
|
module.exports = { ...nxPreset }`);
|
|
37
|
-
|
|
37
|
+
updateProductionFileSet(tree);
|
|
38
|
+
addJestTargetDefaults(tree);
|
|
38
39
|
}
|
|
39
40
|
if (options.rootProject) {
|
|
40
41
|
// we don't want any config to be made because the `configurationGenerator` will do it.
|
|
@@ -73,7 +74,7 @@ function createJestConfig(tree, options) {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
|
-
function
|
|
77
|
+
function updateProductionFileSet(tree) {
|
|
77
78
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
78
79
|
const productionFileSet = nxJson.namedInputs?.production;
|
|
79
80
|
if (productionFileSet) {
|
|
@@ -91,14 +92,29 @@ function addTestInputs(tree) {
|
|
|
91
92
|
// Dedupe and set
|
|
92
93
|
nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
96
|
+
}
|
|
97
|
+
function addJestTargetDefaults(tree) {
|
|
98
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
99
|
+
const productionFileSet = nxJson.namedInputs?.production;
|
|
95
100
|
nxJson.targetDefaults ??= {};
|
|
96
|
-
nxJson.targetDefaults
|
|
97
|
-
nxJson.targetDefaults.
|
|
101
|
+
nxJson.targetDefaults['@nx/jest:jest'] ??= {};
|
|
102
|
+
nxJson.targetDefaults['@nx/jest:jest'].cache ??= true;
|
|
103
|
+
// Test targets depend on all their project's sources + production sources of dependencies
|
|
104
|
+
nxJson.targetDefaults['@nx/jest:jest'].inputs ??= [
|
|
98
105
|
'default',
|
|
99
106
|
productionFileSet ? '^production' : '^default',
|
|
107
|
+
'{workspaceRoot}/jest.preset.js',
|
|
100
108
|
];
|
|
101
|
-
nxJson.targetDefaults
|
|
109
|
+
nxJson.targetDefaults['@nx/jest:jest'].options ??= {
|
|
110
|
+
passWithNoTests: true,
|
|
111
|
+
};
|
|
112
|
+
nxJson.targetDefaults['@nx/jest:jest'].configurations ??= {
|
|
113
|
+
ci: {
|
|
114
|
+
ci: true,
|
|
115
|
+
codeCoverage: true,
|
|
116
|
+
},
|
|
117
|
+
};
|
|
102
118
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
103
119
|
}
|
|
104
120
|
function updateDependencies(tree, options) {
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
5
|
+
const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
|
|
6
|
+
async function update(tree) {
|
|
7
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
8
|
+
// Don't override anything if there are already target defaults for jest
|
|
9
|
+
if (nxJson.targetDefaults?.['@nx/jest:jest']) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
nxJson.targetDefaults ??= {};
|
|
13
|
+
/**
|
|
14
|
+
* A set of targets which does not use any other executors
|
|
15
|
+
*/
|
|
16
|
+
const jestTargets = new Set();
|
|
17
|
+
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
|
18
|
+
(0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nx/jest:jest', (value, proj, targetName) => {
|
|
19
|
+
jestTargets.add(targetName);
|
|
20
|
+
});
|
|
21
|
+
// Workspace does not use jest?
|
|
22
|
+
if (jestTargets.size === 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Use the project graph so targets which are inferred are considered
|
|
26
|
+
const projects = graph.nodes;
|
|
27
|
+
const projectMap = (0, devkit_1.getProjects)(tree);
|
|
28
|
+
const jestDefaults = (nxJson.targetDefaults['@nx/jest:jest'] = {});
|
|
29
|
+
// All jest targets have the same name
|
|
30
|
+
if (jestTargets.size === 1) {
|
|
31
|
+
const targetName = Array.from(jestTargets)[0];
|
|
32
|
+
if (nxJson.targetDefaults[targetName]) {
|
|
33
|
+
Object.assign(jestDefaults, nxJson.targetDefaults[targetName]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
jestDefaults.cache ??= true;
|
|
37
|
+
const inputs = ['default'];
|
|
38
|
+
inputs.push(nxJson.namedInputs?.production ? '^production' : '^default');
|
|
39
|
+
if (tree.exists('jest.preset.js')) {
|
|
40
|
+
inputs.push('{workspaceRoot}/jest.preset.js');
|
|
41
|
+
}
|
|
42
|
+
jestDefaults.inputs ??= inputs;
|
|
43
|
+
// Remember if there were already defaults so we don't assume the executor default
|
|
44
|
+
const passWithNoTestsPreviouslyInDefaults = jestDefaults.options?.passWithNoTests !== undefined;
|
|
45
|
+
const ciCiPreviouslyInDefaults = jestDefaults.configurations?.ci?.ci !== undefined;
|
|
46
|
+
const ciCodeCoveragePreviouslyInDefaults = jestDefaults.configurations?.ci?.codeCoverage !== undefined;
|
|
47
|
+
jestDefaults.options ??= {};
|
|
48
|
+
jestDefaults.options.passWithNoTests ??= true;
|
|
49
|
+
jestDefaults.configurations ??= {};
|
|
50
|
+
jestDefaults.configurations.ci ??= {};
|
|
51
|
+
jestDefaults.configurations.ci.ci ??= true;
|
|
52
|
+
jestDefaults.configurations.ci.codeCoverage ??= true;
|
|
53
|
+
// Cleanup old target defaults
|
|
54
|
+
for (const [targetDefaultKey, targetDefault] of Object.entries(nxJson.targetDefaults)) {
|
|
55
|
+
if (!isTargetDefaultUsed(targetDefault, nxJson.targetDefaults, projects, projectMap)) {
|
|
56
|
+
delete nxJson.targetDefaults[targetDefaultKey];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
60
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/jest:jest', (value, proj, targetName, configuration) => {
|
|
61
|
+
const projConfig = projectMap.get(proj);
|
|
62
|
+
if (!configuration) {
|
|
63
|
+
// Options
|
|
64
|
+
if (value.passWithNoTests === jestDefaults.options.passWithNoTests) {
|
|
65
|
+
delete projConfig.targets[targetName].options.passWithNoTests;
|
|
66
|
+
}
|
|
67
|
+
else if (!passWithNoTestsPreviouslyInDefaults) {
|
|
68
|
+
projConfig.targets[targetName].options.passWithNoTests ??= false;
|
|
69
|
+
}
|
|
70
|
+
if (Object.keys(projConfig.targets[targetName].options).length === 0) {
|
|
71
|
+
delete projConfig.targets[targetName].options;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (configuration === 'ci') {
|
|
75
|
+
// CI Config
|
|
76
|
+
if (value.ci === jestDefaults.configurations.ci.ci) {
|
|
77
|
+
delete projConfig.targets[targetName].configurations.ci.ci;
|
|
78
|
+
}
|
|
79
|
+
else if (ciCiPreviouslyInDefaults) {
|
|
80
|
+
projConfig.targets[targetName].configurations.ci.ci ??= false;
|
|
81
|
+
}
|
|
82
|
+
if (value.codeCoverage === jestDefaults.configurations.ci.codeCoverage) {
|
|
83
|
+
delete projConfig.targets[targetName].configurations.ci.codeCoverage;
|
|
84
|
+
}
|
|
85
|
+
else if (ciCodeCoveragePreviouslyInDefaults) {
|
|
86
|
+
projConfig.targets[targetName].configurations.ci.codeCoverage ??=
|
|
87
|
+
false;
|
|
88
|
+
}
|
|
89
|
+
if (Object.keys(projConfig.targets[targetName].configurations.ci)
|
|
90
|
+
.length === 0) {
|
|
91
|
+
delete projConfig.targets[targetName].configurations.ci;
|
|
92
|
+
}
|
|
93
|
+
if (Object.keys(projConfig.targets[targetName].configurations).length ===
|
|
94
|
+
0) {
|
|
95
|
+
delete projConfig.targets[targetName].configurations;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
(0, devkit_1.updateProjectConfiguration)(tree, proj, projConfig);
|
|
99
|
+
});
|
|
100
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
101
|
+
}
|
|
102
|
+
exports.default = update;
|
|
103
|
+
/**
|
|
104
|
+
* Checks every target on every project to see if one of them uses the target default
|
|
105
|
+
*/
|
|
106
|
+
function isTargetDefaultUsed(targetDefault, targetDefaults, projects, projectMap) {
|
|
107
|
+
for (const p of Object.values(projects)) {
|
|
108
|
+
for (const targetName in p.data?.targets ?? {}) {
|
|
109
|
+
if ((0, project_configuration_utils_1.readTargetDefaultsForTarget)(targetName, targetDefaults,
|
|
110
|
+
// It might seem like we should use the graph here too but we don't want to pass an executor which was processed in the graph
|
|
111
|
+
projectMap.get(p.name).targets?.[targetName]?.executor) === targetDefault) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|