@nx/jest 16.8.0-beta.4 → 16.8.0-beta.6
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 +5 -5
- package/plugins/resolver.js +10 -3
- package/src/executors/jest/jest.impl.js +144 -116
- package/src/executors/jest/summary.js +4 -4
- package/src/generators/configuration/configuration.js +16 -15
- package/src/generators/configuration/lib/check-for-test-target.js +1 -2
- package/src/generators/configuration/lib/create-files.js +11 -3
- package/src/generators/configuration/lib/update-workspace.js +1 -2
- package/src/generators/init/init.js +27 -27
- package/src/migrations/update-12-1-2/update-jest-preset-angular.js +5 -8
- package/src/migrations/update-12-1-2/update-ts-jest.js +5 -9
- package/src/migrations/update-12-4-0/add-test-environment-for-node.js +5 -8
- package/src/migrations/update-12-4-0/update-jest-preset-angular.js +14 -20
- package/src/migrations/update-12-6-0/update-base-jest-config.js +4 -8
- package/src/migrations/update-13-1-2/update-tsconfigs-for-tests.js +3 -6
- package/src/migrations/update-13-4-4/add-missing-root-babel-config.js +7 -10
- package/src/migrations/update-14-0-0/update-jest-config-ext.js +46 -50
- package/src/migrations/update-14-6-0/update-configs-jest-28.js +6 -7
- package/src/migrations/update-14-6-0/update-tests-jest-28.js +12 -16
- package/src/migrations/update-15-0-0/add-jest-inputs.js +27 -32
- package/src/migrations/update-15-8-0/update-configs-jest-29.js +28 -34
- package/src/migrations/update-15-8-0/update-tests-jest-29.js +11 -14
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-5-0/add-test-setup-to-inputs-ignore.js +11 -15
- package/src/utils/config/functions.js +3 -5
- package/src/utils/config/get-jest-projects.js +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "16.8.0-beta.
|
|
3
|
+
"version": "16.8.0-beta.6",
|
|
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": {
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@jest/reporters": "^29.4.1",
|
|
38
38
|
"@jest/test-result": "^29.4.1",
|
|
39
|
-
"@nrwl/jest": "16.8.0-beta.
|
|
40
|
-
"@nx/devkit": "16.8.0-beta.
|
|
41
|
-
"@nx/js": "16.8.0-beta.
|
|
39
|
+
"@nrwl/jest": "16.8.0-beta.6",
|
|
40
|
+
"@nx/devkit": "16.8.0-beta.6",
|
|
41
|
+
"@nx/js": "16.8.0-beta.6",
|
|
42
42
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
43
43
|
"chalk": "^4.1.0",
|
|
44
44
|
"identity-obj-proxy": "3.0.0",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"type": "commonjs",
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "0cc6ba996f2ef09f00b932c8eacf42de642457f3"
|
|
56
56
|
}
|
package/plugins/resolver.js
CHANGED
|
@@ -31,14 +31,21 @@ module.exports = function (path, options) {
|
|
|
31
31
|
// Try to use the defaultResolver with default options
|
|
32
32
|
return options.defaultResolver(path, options);
|
|
33
33
|
}
|
|
34
|
-
catch
|
|
34
|
+
catch {
|
|
35
35
|
// Try to use the defaultResolver with a packageFilter
|
|
36
|
-
return options.defaultResolver(path,
|
|
36
|
+
return options.defaultResolver(path, {
|
|
37
|
+
...options,
|
|
38
|
+
packageFilter: (pkg) => ({
|
|
39
|
+
...pkg,
|
|
40
|
+
main: pkg.main || pkg.es2015 || pkg.module,
|
|
41
|
+
}),
|
|
42
|
+
pathFilter: (pkg) => {
|
|
37
43
|
if (!pkg.exports) {
|
|
38
44
|
return path;
|
|
39
45
|
}
|
|
40
46
|
return (0, resolve_exports_1.resolve)(pkg, path) || path;
|
|
41
|
-
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
51
|
catch (e) {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
var _b;
|
|
4
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
3
|
exports.batchJest = exports.jestConfigParser = exports.jestExecutor = void 0;
|
|
6
|
-
const tslib_1 = require("tslib");
|
|
7
4
|
const jest_1 = require("jest");
|
|
8
5
|
const jest_config_1 = require("jest-config");
|
|
9
6
|
const reporters_1 = require("@jest/reporters");
|
|
@@ -13,13 +10,11 @@ const path_1 = require("path");
|
|
|
13
10
|
const devkit_1 = require("@nx/devkit");
|
|
14
11
|
const summary_1 = require("./summary");
|
|
15
12
|
const fs_1 = require("fs");
|
|
16
|
-
|
|
17
|
-
function jestExecutor(options, context) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return { success: results.success };
|
|
22
|
-
});
|
|
13
|
+
process.env.NODE_ENV ??= 'test';
|
|
14
|
+
async function jestExecutor(options, context) {
|
|
15
|
+
const config = await jestConfigParser(options, context);
|
|
16
|
+
const { results } = await (0, jest_1.runCLI)(config, [options.jestConfig]);
|
|
17
|
+
return { success: results.success };
|
|
23
18
|
}
|
|
24
19
|
exports.jestExecutor = jestExecutor;
|
|
25
20
|
function getExtraArgs(options, schema) {
|
|
@@ -31,121 +26,154 @@ function getExtraArgs(options, schema) {
|
|
|
31
26
|
}
|
|
32
27
|
return extraArgs;
|
|
33
28
|
}
|
|
34
|
-
function jestConfigParser(options, context, multiProjects = false) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
29
|
+
async function jestConfigParser(options, context, multiProjects = false) {
|
|
30
|
+
let jestConfig;
|
|
31
|
+
// support passing extra args to jest cli supporting 3rd party plugins
|
|
32
|
+
// like 'jest-runner-groups' --group arg
|
|
33
|
+
const schema = await Promise.resolve().then(() => require('./schema.json'));
|
|
34
|
+
const extraArgs = getExtraArgs(options, schema);
|
|
35
|
+
const config = {
|
|
36
|
+
...extraArgs,
|
|
37
|
+
$0: undefined,
|
|
38
|
+
_: [],
|
|
39
|
+
config: options.config,
|
|
40
|
+
coverage: options.codeCoverage,
|
|
41
|
+
bail: options.bail,
|
|
42
|
+
ci: options.ci,
|
|
43
|
+
color: options.color,
|
|
44
|
+
detectOpenHandles: options.detectOpenHandles,
|
|
45
|
+
forceExit: options.forceExit,
|
|
46
|
+
logHeapUsage: options.logHeapUsage,
|
|
47
|
+
detectLeaks: options.detectLeaks,
|
|
48
|
+
json: options.json,
|
|
49
|
+
maxWorkers: options.maxWorkers,
|
|
50
|
+
onlyChanged: options.onlyChanged,
|
|
51
|
+
changedSince: options.changedSince,
|
|
52
|
+
outputFile: options.outputFile,
|
|
53
|
+
passWithNoTests: options.passWithNoTests,
|
|
54
|
+
runInBand: options.runInBand,
|
|
55
|
+
showConfig: options.showConfig,
|
|
56
|
+
silent: options.silent,
|
|
57
|
+
testLocationInResults: options.testLocationInResults,
|
|
58
|
+
testNamePattern: options.testNamePattern,
|
|
59
|
+
testPathPattern: options.testPathPattern,
|
|
60
|
+
testPathIgnorePatterns: options.testPathIgnorePatterns,
|
|
61
|
+
testTimeout: options.testTimeout,
|
|
62
|
+
colors: options.colors,
|
|
63
|
+
verbose: options.verbose,
|
|
64
|
+
testResultsProcessor: options.testResultsProcessor,
|
|
65
|
+
updateSnapshot: options.updateSnapshot,
|
|
66
|
+
useStderr: options.useStderr,
|
|
67
|
+
watch: options.watch,
|
|
68
|
+
watchAll: options.watchAll,
|
|
69
|
+
randomize: options.randomize,
|
|
70
|
+
};
|
|
71
|
+
if (!multiProjects) {
|
|
72
|
+
options.jestConfig = path.resolve(context.root, options.jestConfig);
|
|
73
|
+
jestConfig = (await (0, jest_config_1.readConfig)(config, options.jestConfig)).projectConfig;
|
|
74
|
+
}
|
|
75
|
+
// for backwards compatibility
|
|
76
|
+
if (options.setupFile && !multiProjects) {
|
|
77
|
+
const setupFilesAfterEnvSet = new Set([
|
|
78
|
+
...(jestConfig.setupFilesAfterEnv ?? []),
|
|
79
|
+
path.resolve(context.root, options.setupFile),
|
|
80
|
+
]);
|
|
81
|
+
config.setupFilesAfterEnv = Array.from(setupFilesAfterEnvSet);
|
|
82
|
+
}
|
|
83
|
+
if (options.testFile) {
|
|
84
|
+
config._.push(options.testFile);
|
|
85
|
+
}
|
|
86
|
+
if (options.findRelatedTests) {
|
|
87
|
+
const parsedTests = options.findRelatedTests
|
|
88
|
+
.split(',')
|
|
89
|
+
.map((s) => s.trim());
|
|
90
|
+
config._.push(...parsedTests);
|
|
91
|
+
config.findRelatedTests = true;
|
|
92
|
+
}
|
|
93
|
+
if (options.coverageDirectory) {
|
|
94
|
+
config.coverageDirectory = path.join(context.root, options.coverageDirectory);
|
|
95
|
+
}
|
|
96
|
+
if (options.clearCache) {
|
|
97
|
+
config.clearCache = true;
|
|
98
|
+
}
|
|
99
|
+
if (options.reporters && options.reporters.length > 0) {
|
|
100
|
+
config.reporters = options.reporters;
|
|
101
|
+
}
|
|
102
|
+
if (Array.isArray(options.coverageReporters) &&
|
|
103
|
+
options.coverageReporters.length > 0) {
|
|
104
|
+
config.coverageReporters = options.coverageReporters;
|
|
105
|
+
}
|
|
106
|
+
return config;
|
|
80
107
|
}
|
|
81
108
|
exports.jestConfigParser = jestConfigParser;
|
|
82
109
|
exports.default = jestExecutor;
|
|
83
|
-
function batchJest(taskGraph, inputs, overrides, context) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const displayName = fileContents
|
|
102
|
-
.match(displayNameValueRegex)
|
|
103
|
-
.map((value) => value.substring(1, value.length - 1))[0];
|
|
104
|
-
selectedProjects.push(displayName);
|
|
110
|
+
async function batchJest(taskGraph, inputs, overrides, context) {
|
|
111
|
+
let configPaths = [];
|
|
112
|
+
let selectedProjects = [];
|
|
113
|
+
let projectsWithNoName = [];
|
|
114
|
+
for (const task of taskGraph.roots) {
|
|
115
|
+
let configPath = path.resolve(context.root, inputs[task].jestConfig);
|
|
116
|
+
configPaths.push(configPath);
|
|
117
|
+
/* The display name in the jest.config.js is the correct project name jest
|
|
118
|
+
* uses to determine projects. It is usually the same as the Nx projectName
|
|
119
|
+
* but it can be changed. The safest method is to extract the displayName
|
|
120
|
+
* from the config file, but skip the project if it does not exist. */
|
|
121
|
+
const displayNameValueRegex = new RegExp(/(['"]+.*['"])(?<=displayName+.*)/, 'g');
|
|
122
|
+
const fileContents = (0, fs_1.readFileSync)(configPath, { encoding: 'utf-8' });
|
|
123
|
+
if (!displayNameValueRegex.test(fileContents)) {
|
|
124
|
+
projectsWithNoName.push([task.split(':')[0], configPath]);
|
|
125
|
+
continue;
|
|
105
126
|
}
|
|
106
|
-
|
|
107
|
-
|
|
127
|
+
const displayName = fileContents
|
|
128
|
+
.match(displayNameValueRegex)
|
|
129
|
+
.map((value) => value.substring(1, value.length - 1))[0];
|
|
130
|
+
selectedProjects.push(displayName);
|
|
131
|
+
}
|
|
132
|
+
if (projectsWithNoName.length > 0) {
|
|
133
|
+
throw new Error((0, devkit_1.stripIndents) `Some projects do not have a "displayName" property. Jest Batch Mode requires this to be set. Please ensure this value is set.
|
|
108
134
|
|
|
109
135
|
Projects missing "displayName":
|
|
110
136
|
${projectsWithNoName.map(([project, configPath]) => ` - ${project} - ${configPath}\r\n`)}
|
|
111
137
|
You can learn more about this requirement from Jest here: https://jestjs.io/docs/cli#--selectprojects-project1--projectn`);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
}
|
|
139
|
+
const parsedConfigs = await jestConfigParser(overrides, context, true);
|
|
140
|
+
const { globalConfig, results } = await (0, jest_1.runCLI)({
|
|
141
|
+
...parsedConfigs,
|
|
142
|
+
selectProjects: selectedProjects,
|
|
143
|
+
}, [devkit_1.workspaceRoot]);
|
|
144
|
+
const { configs } = await (0, jest_config_1.readConfigs)({ $0: undefined, _: [] }, configPaths);
|
|
145
|
+
const jestTaskExecutionResults = {};
|
|
146
|
+
for (let i = 0; i < taskGraph.roots.length; i++) {
|
|
147
|
+
let root = taskGraph.roots[i];
|
|
148
|
+
const aggregatedResults = (0, test_result_1.makeEmptyAggregatedTestResult)();
|
|
149
|
+
aggregatedResults.startTime = results.startTime;
|
|
150
|
+
let endTime;
|
|
151
|
+
const projectRoot = (0, path_1.join)(context.root, taskGraph.tasks[root].projectRoot);
|
|
152
|
+
let resultOutput = '';
|
|
153
|
+
for (const testResult of results.testResults) {
|
|
154
|
+
if (testResult.testFilePath.startsWith(projectRoot)) {
|
|
155
|
+
aggregatedResults.startTime = aggregatedResults.startTime
|
|
156
|
+
? Math.min(aggregatedResults.startTime, testResult.perfStats.start)
|
|
157
|
+
: testResult.perfStats.start;
|
|
158
|
+
endTime = endTime
|
|
159
|
+
? Math.max(testResult.perfStats.end, endTime)
|
|
160
|
+
: testResult.perfStats.end;
|
|
161
|
+
(0, test_result_1.addResult)(aggregatedResults, testResult);
|
|
162
|
+
resultOutput +=
|
|
163
|
+
'\n\r' +
|
|
164
|
+
reporters_1.utils.getResultHeader(testResult, globalConfig, configs[i]);
|
|
137
165
|
}
|
|
138
|
-
aggregatedResults.numTotalTestSuites = aggregatedResults.testResults.length;
|
|
139
|
-
jestTaskExecutionResults[root] = {
|
|
140
|
-
startTime: aggregatedResults.startTime,
|
|
141
|
-
endTime,
|
|
142
|
-
success: aggregatedResults.numFailedTests === 0,
|
|
143
|
-
// TODO(caleb): getSummary assumed endTime is Date.now().
|
|
144
|
-
// might need to make own method to correctly set the endtime base on tests instead of _now_
|
|
145
|
-
terminalOutput: resultOutput + '\n\r\n\r' + (0, summary_1.getSummary)(aggregatedResults),
|
|
146
|
-
};
|
|
147
166
|
}
|
|
148
|
-
|
|
149
|
-
|
|
167
|
+
aggregatedResults.numTotalTestSuites = aggregatedResults.testResults.length;
|
|
168
|
+
jestTaskExecutionResults[root] = {
|
|
169
|
+
startTime: aggregatedResults.startTime,
|
|
170
|
+
endTime,
|
|
171
|
+
success: aggregatedResults.numFailedTests === 0,
|
|
172
|
+
// TODO(caleb): getSummary assumed endTime is Date.now().
|
|
173
|
+
// might need to make own method to correctly set the endtime base on tests instead of _now_
|
|
174
|
+
terminalOutput: resultOutput + '\n\r\n\r' + (0, summary_1.getSummary)(aggregatedResults),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return jestTaskExecutionResults;
|
|
150
178
|
}
|
|
151
179
|
exports.batchJest = batchJest;
|
|
@@ -68,11 +68,11 @@ const renderTime = (runTime, estimatedTime, width) => {
|
|
|
68
68
|
};
|
|
69
69
|
const getSummary = (aggregatedResults, options) => {
|
|
70
70
|
let runTime = (Date.now() - aggregatedResults.startTime) / 1000;
|
|
71
|
-
if (options
|
|
71
|
+
if (options?.roundTime) {
|
|
72
72
|
runTime = Math.floor(runTime);
|
|
73
73
|
}
|
|
74
|
-
const { numFailingTests, numPendingTests, numTodoTests, numPassingTests, numTotalTests, } = getValuesCurrentTestCases(options
|
|
75
|
-
const estimatedTime =
|
|
74
|
+
const { numFailingTests, numPendingTests, numTodoTests, numPassingTests, numTotalTests, } = getValuesCurrentTestCases(options?.currentTestCases);
|
|
75
|
+
const estimatedTime = options?.estimatedTime || 0;
|
|
76
76
|
const snapshotResults = aggregatedResults.snapshot;
|
|
77
77
|
const snapshotsAdded = snapshotResults.added;
|
|
78
78
|
const snapshotsFailed = snapshotResults.unmatched;
|
|
@@ -92,7 +92,7 @@ const getSummary = (aggregatedResults, options) => {
|
|
|
92
92
|
const testsPending = aggregatedResults.numPendingTests;
|
|
93
93
|
const testsTodo = aggregatedResults.numTodoTests;
|
|
94
94
|
const testsTotal = aggregatedResults.numTotalTests;
|
|
95
|
-
const width =
|
|
95
|
+
const width = options?.width || 0;
|
|
96
96
|
const suites = chalk.bold('Test Suites: ') +
|
|
97
97
|
(suitesFailed ? chalk.bold.red(`${suitesFailed} failed`) + ', ' : '') +
|
|
98
98
|
(suitesPending
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.compat = exports.configurationGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const init_1 = require("../init/init");
|
|
6
5
|
const check_for_test_target_1 = require("./lib/check-for-test-target");
|
|
7
6
|
const create_files_1 = require("./lib/create-files");
|
|
@@ -34,21 +33,23 @@ function normalizeOptions(tree, options) {
|
|
|
34
33
|
options.setupFile = schemaDefaults.setupFile;
|
|
35
34
|
}
|
|
36
35
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
37
|
-
return
|
|
36
|
+
return {
|
|
37
|
+
...schemaDefaults,
|
|
38
|
+
...options,
|
|
39
|
+
rootProject: project.root === '.' || project.root === '',
|
|
40
|
+
};
|
|
38
41
|
}
|
|
39
|
-
function configurationGenerator(tree, schema) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return installTask;
|
|
51
|
-
});
|
|
42
|
+
async function configurationGenerator(tree, schema) {
|
|
43
|
+
const options = normalizeOptions(tree, schema);
|
|
44
|
+
const installTask = await (0, init_1.default)(tree, options);
|
|
45
|
+
(0, check_for_test_target_1.checkForTestTarget)(tree, options);
|
|
46
|
+
(0, create_files_1.createFiles)(tree, options);
|
|
47
|
+
(0, update_tsconfig_1.updateTsConfig)(tree, options);
|
|
48
|
+
(0, update_workspace_1.updateWorkspace)(tree, options);
|
|
49
|
+
if (!schema.skipFormat) {
|
|
50
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
51
|
+
}
|
|
52
|
+
return installTask;
|
|
52
53
|
}
|
|
53
54
|
exports.configurationGenerator = configurationGenerator;
|
|
54
55
|
exports.default = configurationGenerator;
|
|
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.checkForTestTarget = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
function checkForTestTarget(tree, options) {
|
|
6
|
-
var _a;
|
|
7
6
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
8
|
-
if (
|
|
7
|
+
if (projectConfig?.targets?.test) {
|
|
9
8
|
throw new Error(`${options.project}: already has a test target set.`);
|
|
10
9
|
}
|
|
11
10
|
}
|
|
@@ -22,12 +22,20 @@ function createFiles(tree, options) {
|
|
|
22
22
|
transformer = 'ts-jest';
|
|
23
23
|
transformerOptions = "{ tsconfig: '<rootDir>/tsconfig.spec.json' }";
|
|
24
24
|
}
|
|
25
|
-
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, filesFolder), projectConfig.root,
|
|
25
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, filesFolder), projectConfig.root, {
|
|
26
|
+
tmpl: '',
|
|
27
|
+
...options,
|
|
26
28
|
// jsdom is the default
|
|
27
29
|
testEnvironment: options.testEnvironment === 'none' || options.testEnvironment === 'jsdom'
|
|
28
30
|
? ''
|
|
29
|
-
: options.testEnvironment,
|
|
30
|
-
|
|
31
|
+
: options.testEnvironment,
|
|
32
|
+
transformer,
|
|
33
|
+
transformerOptions,
|
|
34
|
+
js: !!options.js,
|
|
35
|
+
rootProject: options.rootProject,
|
|
36
|
+
projectRoot: options.rootProject ? options.project : projectConfig.root,
|
|
37
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(projectConfig.root),
|
|
38
|
+
});
|
|
31
39
|
if (options.setupFile === 'none') {
|
|
32
40
|
tree.delete((0, path_1.join)(projectConfig.root, './src/test-setup.ts'));
|
|
33
41
|
}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateWorkspace = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
function updateWorkspace(tree, options) {
|
|
6
|
-
var _a;
|
|
7
6
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
8
7
|
if (!projectConfig.targets) {
|
|
9
8
|
projectConfig.targets = {};
|
|
@@ -29,7 +28,7 @@ function updateWorkspace(tree, options) {
|
|
|
29
28
|
/**
|
|
30
29
|
* @deprecated this will be removed in the v17
|
|
31
30
|
*/
|
|
32
|
-
const isUsingTSLint =
|
|
31
|
+
const isUsingTSLint = projectConfig.targets.lint?.executor ===
|
|
33
32
|
'@angular-devkit/build-angular:tslint';
|
|
34
33
|
if (isUsingTSLint) {
|
|
35
34
|
projectConfig.targets.lint.options.tsConfig = [
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jestInitSchematic = exports.jestInitGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const js_1 = require("@nx/js");
|
|
7
6
|
const find_root_jest_files_1 = require("../../utils/config/find-root-jest-files");
|
|
@@ -29,7 +28,6 @@ function generateGlobalConfig(tree, isJS) {
|
|
|
29
28
|
tree.write(`jest.config.${isJS ? 'js' : 'ts'}`, contents);
|
|
30
29
|
}
|
|
31
30
|
function createJestConfig(tree, options) {
|
|
32
|
-
var _a;
|
|
33
31
|
if (!tree.exists('jest.preset.js')) {
|
|
34
32
|
// preset is always js file.
|
|
35
33
|
tree.write(`jest.preset.js`, `
|
|
@@ -56,13 +54,13 @@ function createJestConfig(tree, options) {
|
|
|
56
54
|
// moving from root project config to monorepo-style config
|
|
57
55
|
const projects = (0, devkit_1.getProjects)(tree);
|
|
58
56
|
const projectNames = Array.from(projects.keys());
|
|
59
|
-
const rootProject = projectNames.find((projectName) =>
|
|
57
|
+
const rootProject = projectNames.find((projectName) => projects.get(projectName)?.root === '.');
|
|
60
58
|
// root project might have been removed,
|
|
61
59
|
// if it's missing there's nothing to migrate
|
|
62
60
|
if (rootProject) {
|
|
63
61
|
const rootProjectConfig = projects.get(rootProject);
|
|
64
|
-
const jestTarget = Object.values(rootProjectConfig.targets || {}).find((t) =>
|
|
65
|
-
const isProjectConfig =
|
|
62
|
+
const jestTarget = Object.values(rootProjectConfig.targets || {}).find((t) => t?.executor === '@nx/jest:jest' || t?.executor === '@nrwl/jest:jest');
|
|
63
|
+
const isProjectConfig = jestTarget?.options?.jestConfig === rootJestPath;
|
|
66
64
|
// if root project doesn't have jest target, there's nothing to migrate
|
|
67
65
|
if (isProjectConfig) {
|
|
68
66
|
const jestProjectConfig = `jest.config.${rootProjectConfig.projectType === 'application' ? 'app' : 'lib'}.${options.js ? 'js' : 'ts'}`;
|
|
@@ -76,10 +74,8 @@ function createJestConfig(tree, options) {
|
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
76
|
function addTestInputs(tree) {
|
|
79
|
-
var _a, _b, _c, _d;
|
|
80
|
-
var _e, _f;
|
|
81
77
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
82
|
-
const productionFileSet =
|
|
78
|
+
const productionFileSet = nxJson.namedInputs?.production;
|
|
83
79
|
if (productionFileSet) {
|
|
84
80
|
// This is one of the patterns in the default jest patterns
|
|
85
81
|
productionFileSet.push(
|
|
@@ -96,12 +92,12 @@ function addTestInputs(tree) {
|
|
|
96
92
|
nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
|
|
97
93
|
}
|
|
98
94
|
// Test targets depend on all their project's sources + production sources of dependencies
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
nxJson.targetDefaults ??= {};
|
|
96
|
+
nxJson.targetDefaults.test ??= {};
|
|
97
|
+
nxJson.targetDefaults.test.inputs ??= [
|
|
102
98
|
'default',
|
|
103
99
|
productionFileSet ? '^production' : '^default',
|
|
104
|
-
]
|
|
100
|
+
];
|
|
105
101
|
nxJson.targetDefaults.test.inputs.push('{workspaceRoot}/jest.preset.js');
|
|
106
102
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
107
103
|
}
|
|
@@ -148,24 +144,28 @@ function updateExtensions(host) {
|
|
|
148
144
|
return json;
|
|
149
145
|
});
|
|
150
146
|
}
|
|
151
|
-
function jestInitGenerator(tree, schema) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
147
|
+
async function jestInitGenerator(tree, schema) {
|
|
148
|
+
const options = normalizeOptions(schema);
|
|
149
|
+
const tasks = [];
|
|
150
|
+
tasks.push(await (0, js_1.initGenerator)(tree, {
|
|
151
|
+
...schema,
|
|
152
|
+
skipFormat: true,
|
|
153
|
+
}));
|
|
154
|
+
createJestConfig(tree, options);
|
|
155
|
+
if (!options.skipPackageJson) {
|
|
156
|
+
(0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@nx/jest'], []);
|
|
157
|
+
const installTask = updateDependencies(tree, options);
|
|
158
|
+
tasks.push(installTask);
|
|
159
|
+
}
|
|
160
|
+
updateExtensions(tree);
|
|
161
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
165
162
|
}
|
|
166
163
|
exports.jestInitGenerator = jestInitGenerator;
|
|
167
164
|
function normalizeOptions(options) {
|
|
168
|
-
return
|
|
165
|
+
return {
|
|
166
|
+
...schemaDefaults,
|
|
167
|
+
...options,
|
|
168
|
+
};
|
|
169
169
|
}
|
|
170
170
|
exports.default = jestInitGenerator;
|
|
171
171
|
exports.jestInitSchematic = (0, devkit_1.convertNxGenerator)(jestInitGenerator);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
3
|
const devkit_1 = require("@nx/devkit");
|
|
5
4
|
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
5
|
const path_1 = require("path");
|
|
@@ -27,7 +26,7 @@ function updateJestConfig(tree) {
|
|
|
27
26
|
(0, update_config_1.removePropertyFromJestConfig)(tree, options.jestConfig, 'snapshotSerializers');
|
|
28
27
|
(0, update_config_1.addPropertyToJestConfig)(tree, options.jestConfig, 'snapshotSerializers', snapshotSerializers);
|
|
29
28
|
}
|
|
30
|
-
catch
|
|
29
|
+
catch {
|
|
31
30
|
devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update snapshotSerializers for project ${projectName}.
|
|
32
31
|
More information you can check online documentation https://github.com/thymikee/jest-preset-angular/blob/master/CHANGELOG.md#840-2021-03-04`);
|
|
33
32
|
}
|
|
@@ -40,15 +39,13 @@ function updateJestConfig(tree) {
|
|
|
40
39
|
tree.write(setupTestPath, contents.replace(`import 'jest-preset-angular';`, `import 'jest-preset-angular/setup-jest';`));
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
catch
|
|
42
|
+
catch {
|
|
44
43
|
devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update test-setup.ts for project ${projectName}.`);
|
|
45
44
|
}
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
|
-
function update(tree) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
yield (0, devkit_1.formatFiles)(tree);
|
|
52
|
-
});
|
|
47
|
+
async function update(tree) {
|
|
48
|
+
updateJestConfig(tree);
|
|
49
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
53
50
|
}
|
|
54
51
|
exports.default = update;
|