@nx/jest 21.2.2 → 21.2.4
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 +3 -3
- package/src/plugins/plugin.js +35 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "21.2.
|
|
3
|
+
"version": "21.2.4",
|
|
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": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@jest/reporters": "^29.4.1",
|
|
39
39
|
"@jest/test-result": "^29.4.1",
|
|
40
|
-
"@nx/devkit": "21.2.
|
|
41
|
-
"@nx/js": "21.2.
|
|
40
|
+
"@nx/devkit": "21.2.4",
|
|
41
|
+
"@nx/js": "21.2.4",
|
|
42
42
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
43
43
|
"identity-obj-proxy": "3.0.0",
|
|
44
44
|
"jest-config": "^29.4.1",
|
package/src/plugins/plugin.js
CHANGED
|
@@ -32,11 +32,11 @@ exports.createNodesV2 = [
|
|
|
32
32
|
const targetsCache = readTargetsCache(cachePath);
|
|
33
33
|
// Cache jest preset(s) to avoid penalties of module load times. Most of jest configs will use the same preset.
|
|
34
34
|
const presetCache = {};
|
|
35
|
-
const
|
|
35
|
+
const isInPackageManagerWorkspaces = buildPackageJsonWorkspacesMatcher(context.workspaceRoot);
|
|
36
36
|
options = normalizeOptions(options);
|
|
37
37
|
const { roots: projectRoots, configFiles: validConfigFiles } = configFiles.reduce((acc, configFile) => {
|
|
38
38
|
const potentialRoot = (0, path_1.dirname)(configFile);
|
|
39
|
-
if (checkIfConfigFileShouldBeProject(configFile, potentialRoot,
|
|
39
|
+
if (checkIfConfigFileShouldBeProject(configFile, potentialRoot, isInPackageManagerWorkspaces, context)) {
|
|
40
40
|
acc.roots.push(potentialRoot);
|
|
41
41
|
acc.configFiles.push(configFile);
|
|
42
42
|
}
|
|
@@ -77,8 +77,8 @@ exports.createNodes = [
|
|
|
77
77
|
async (configFilePath, options, context) => {
|
|
78
78
|
devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
|
|
79
79
|
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
80
|
-
const
|
|
81
|
-
if (!checkIfConfigFileShouldBeProject(configFilePath, projectRoot,
|
|
80
|
+
const isInPackageManagerWorkspaces = buildPackageJsonWorkspacesMatcher(context.workspaceRoot);
|
|
81
|
+
if (!checkIfConfigFileShouldBeProject(configFilePath, projectRoot, isInPackageManagerWorkspaces, context)) {
|
|
82
82
|
return {};
|
|
83
83
|
}
|
|
84
84
|
options = normalizeOptions(options);
|
|
@@ -94,7 +94,14 @@ exports.createNodes = [
|
|
|
94
94
|
};
|
|
95
95
|
},
|
|
96
96
|
];
|
|
97
|
-
function
|
|
97
|
+
function buildPackageJsonWorkspacesMatcher(workspaceRoot) {
|
|
98
|
+
if (process.env.NX_INFER_ALL_PACKAGE_JSONS === 'true') {
|
|
99
|
+
return () => true;
|
|
100
|
+
}
|
|
101
|
+
const packageManagerWorkspacesGlob = (0, globs_1.combineGlobPatterns)((0, package_json_1.getGlobPatternsFromPackageManagerWorkspaces)(workspaceRoot));
|
|
102
|
+
return (path) => (0, minimatch_1.minimatch)(path, packageManagerWorkspacesGlob);
|
|
103
|
+
}
|
|
104
|
+
function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, isInPackageManagerWorkspaces, context) {
|
|
98
105
|
// Do not create a project if package.json and project.json isn't there.
|
|
99
106
|
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
100
107
|
if (!siblingFiles.includes('package.json') &&
|
|
@@ -104,7 +111,7 @@ function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, packageMa
|
|
|
104
111
|
else if (!siblingFiles.includes('project.json') &&
|
|
105
112
|
siblingFiles.includes('package.json')) {
|
|
106
113
|
const path = (0, devkit_1.joinPathFragments)(projectRoot, 'package.json');
|
|
107
|
-
const isPackageJsonProject = (
|
|
114
|
+
const isPackageJsonProject = isInPackageManagerWorkspaces(path);
|
|
108
115
|
if (!isPackageJsonProject) {
|
|
109
116
|
return false;
|
|
110
117
|
}
|
|
@@ -169,7 +176,7 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
|
|
|
169
176
|
? (0, path_1.join)(context.workspaceRoot, projectRoot, rawConfig.coverageDirectory)
|
|
170
177
|
: undefined, undefined, context));
|
|
171
178
|
if (options?.ciTargetName) {
|
|
172
|
-
const
|
|
179
|
+
const { specs, testMatch } = await getTestPaths(projectRoot, rawConfig, absConfigFilePath, context, presetCache);
|
|
173
180
|
const targetGroup = [];
|
|
174
181
|
const dependsOn = [];
|
|
175
182
|
metadata = {
|
|
@@ -178,8 +185,18 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
|
|
|
178
185
|
},
|
|
179
186
|
};
|
|
180
187
|
const specIgnoreRegexes = rawConfig.testPathIgnorePatterns?.map((p) => new RegExp(replaceRootDirInPath(projectRoot, p)));
|
|
181
|
-
for (const testPath of
|
|
188
|
+
for (const testPath of specs) {
|
|
182
189
|
const relativePath = (0, devkit_1.normalizePath)((0, path_1.relative)((0, path_1.join)(context.workspaceRoot, projectRoot), testPath));
|
|
190
|
+
if (relativePath.includes('../')) {
|
|
191
|
+
throw new Error('@nx/jest/plugin attempted to run tests outside of the project root. This is not supported and should not happen. Please open an issue at https://github.com/nrwl/nx/issues/new/choose with the following information:\n\n' +
|
|
192
|
+
`\n\n${JSON.stringify({
|
|
193
|
+
projectRoot,
|
|
194
|
+
relativePath,
|
|
195
|
+
specs,
|
|
196
|
+
context,
|
|
197
|
+
testMatch,
|
|
198
|
+
}, null, 2)}`);
|
|
199
|
+
}
|
|
183
200
|
if (specIgnoreRegexes?.some((regex) => regex.test(relativePath))) {
|
|
184
201
|
continue;
|
|
185
202
|
}
|
|
@@ -293,6 +310,15 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
|
|
|
293
310
|
targetGroup.push(options.ciTargetName);
|
|
294
311
|
for (const testPath of testPaths) {
|
|
295
312
|
const relativePath = (0, devkit_1.normalizePath)((0, path_1.relative)((0, path_1.join)(context.workspaceRoot, projectRoot), testPath));
|
|
313
|
+
if (relativePath.includes('../')) {
|
|
314
|
+
throw new Error('@nx/jest/plugin attempted to run tests outside of the project root. This is not supported and should not happen. Please open an issue at https://github.com/nrwl/nx/issues/new/choose with the following information:\n\n' +
|
|
315
|
+
`\n\n${JSON.stringify({
|
|
316
|
+
projectRoot,
|
|
317
|
+
relativePath,
|
|
318
|
+
testPaths,
|
|
319
|
+
context,
|
|
320
|
+
}, null, 2)}`);
|
|
321
|
+
}
|
|
296
322
|
const targetName = `${options.ciTargetName}--${relativePath}`;
|
|
297
323
|
dependsOn.push(targetName);
|
|
298
324
|
targets[targetName] = {
|
|
@@ -461,7 +487,7 @@ async function getTestPaths(projectRoot, rawConfig, absConfigFilePath, context,
|
|
|
461
487
|
: [new RegExp(rawConfig.testRegex)];
|
|
462
488
|
paths = paths.filter((path) => testRegexes.some((r) => r.test(path)));
|
|
463
489
|
}
|
|
464
|
-
return paths;
|
|
490
|
+
return { specs: paths, testMatch };
|
|
465
491
|
}
|
|
466
492
|
async function getJestOption(rawConfig, absConfigFilePath, optionName, presetCache) {
|
|
467
493
|
if (rawConfig[optionName])
|