@nx/jest 22.1.0-beta.1 → 22.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/package.json +5 -5
- package/src/plugins/plugin.d.ts.map +1 -1
- package/src/plugins/plugin.js +35 -56
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "22.1.0-beta.
|
|
3
|
+
"version": "22.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": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@jest/reporters": "^30.0.2",
|
|
39
39
|
"@jest/test-result": "^30.0.2",
|
|
40
|
-
"@nx/devkit": "22.1.0-beta.
|
|
41
|
-
"@nx/js": "22.1.0-beta.
|
|
40
|
+
"@nx/devkit": "22.1.0-beta.2",
|
|
41
|
+
"@nx/js": "22.1.0-beta.2",
|
|
42
42
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
43
43
|
"identity-obj-proxy": "3.0.0",
|
|
44
44
|
"jest-config": "^30.0.2",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"minimatch": "9.0.3",
|
|
48
48
|
"picocolors": "^1.1.0",
|
|
49
49
|
"resolve.exports": "2.0.3",
|
|
50
|
-
"semver": "^7.
|
|
50
|
+
"semver": "^7.6.3",
|
|
51
51
|
"tslib": "^2.3.0",
|
|
52
52
|
"yargs-parser": "21.1.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"nx": "22.1.0-beta.
|
|
55
|
+
"nx": "22.1.0-beta.2"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/jest/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EASd,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/jest/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EASd,MAAM,YAAY,CAAC;AA6BpB,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAmBD,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC,iBAAiB,CAiFxD,CAAC;AAEF,eAAO,MAAM,aAAa,kCAAc,CAAC"}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -5,21 +5,21 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
6
6
|
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
|
7
7
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
8
|
const minimatch_1 = require("minimatch");
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
10
11
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
11
12
|
const package_json_1 = require("nx/src/plugins/package-json");
|
|
12
13
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
13
14
|
const globs_1 = require("nx/src/utils/globs");
|
|
14
|
-
const path_1 = require("path");
|
|
15
|
-
const workspace_context_1 = require("nx/src/utils/workspace-context");
|
|
16
|
-
const node_path_1 = require("node:path");
|
|
17
15
|
const installation_directory_1 = require("nx/src/utils/installation-directory");
|
|
16
|
+
const plugins_1 = require("nx/src/utils/plugins");
|
|
17
|
+
const workspace_context_1 = require("nx/src/utils/workspace-context");
|
|
18
18
|
const semver_1 = require("semver");
|
|
19
19
|
const versions_1 = require("../utils/versions");
|
|
20
20
|
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
21
21
|
function readTargetsCache(cachePath) {
|
|
22
|
-
return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0,
|
|
22
|
+
return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0, node_fs_1.existsSync)(cachePath)
|
|
23
23
|
? (0, devkit_1.readJsonFile)(cachePath)
|
|
24
24
|
: {};
|
|
25
25
|
}
|
|
@@ -31,14 +31,14 @@ exports.createNodes = [
|
|
|
31
31
|
jestConfigGlob,
|
|
32
32
|
async (configFiles, options, context) => {
|
|
33
33
|
const optionsHash = (0, devkit_internals_1.hashObject)(options);
|
|
34
|
-
const cachePath = (0,
|
|
34
|
+
const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `jest-${optionsHash}.hash`);
|
|
35
35
|
const targetsCache = readTargetsCache(cachePath);
|
|
36
36
|
// Cache jest preset(s) to avoid penalties of module load times. Most of jest configs will use the same preset.
|
|
37
37
|
const presetCache = {};
|
|
38
38
|
const isInPackageManagerWorkspaces = buildPackageJsonWorkspacesMatcher(context.workspaceRoot);
|
|
39
39
|
options = normalizeOptions(options);
|
|
40
40
|
const { roots: projectRoots, configFiles: validConfigFiles } = configFiles.reduce((acc, configFile) => {
|
|
41
|
-
const potentialRoot = (0,
|
|
41
|
+
const potentialRoot = (0, node_path_1.dirname)(configFile);
|
|
42
42
|
if (checkIfConfigFileShouldBeProject(configFile, potentialRoot, isInPackageManagerWorkspaces, context)) {
|
|
43
43
|
acc.roots.push(potentialRoot);
|
|
44
44
|
acc.configFiles.push(configFile);
|
|
@@ -81,7 +81,7 @@ function buildPackageJsonWorkspacesMatcher(workspaceRoot) {
|
|
|
81
81
|
}
|
|
82
82
|
function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, isInPackageManagerWorkspaces, context) {
|
|
83
83
|
// Do not create a project if package.json and project.json isn't there.
|
|
84
|
-
const siblingFiles = (0,
|
|
84
|
+
const siblingFiles = (0, node_fs_1.readdirSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot));
|
|
85
85
|
if (!siblingFiles.includes('package.json') &&
|
|
86
86
|
!siblingFiles.includes('project.json')) {
|
|
87
87
|
return false;
|
|
@@ -94,7 +94,7 @@ function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, isInPacka
|
|
|
94
94
|
return false;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
const jestConfigContent = (0,
|
|
97
|
+
const jestConfigContent = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(context.workspaceRoot, configFilePath), 'utf-8');
|
|
98
98
|
if (jestConfigContent.includes('getJestProjectsAsync()')) {
|
|
99
99
|
// The `getJestProjectsAsync` function uses the project graph, which leads to a
|
|
100
100
|
// circular dependency. We can skip this since it's no intended to be used for
|
|
@@ -104,7 +104,7 @@ function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, isInPacka
|
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
106
|
async function buildJestTargets(configFilePath, projectRoot, options, context, presetCache) {
|
|
107
|
-
const absConfigFilePath = (0,
|
|
107
|
+
const absConfigFilePath = (0, node_path_1.resolve)(context.workspaceRoot, configFilePath);
|
|
108
108
|
if (require.cache[absConfigFilePath])
|
|
109
109
|
(0, config_utils_1.clearRequireCache)();
|
|
110
110
|
const rawConfig = await (0, config_utils_1.loadConfigFile)(absConfigFilePath,
|
|
@@ -161,10 +161,10 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
|
|
|
161
161
|
const cache = (target.cache = true);
|
|
162
162
|
const inputs = (target.inputs = getInputs(namedInputs, rawConfig.preset, projectRoot, context.workspaceRoot, disableJestRuntime));
|
|
163
163
|
let metadata;
|
|
164
|
-
const groupName = options?.ciGroupName ??
|
|
164
|
+
const groupName = options?.ciGroupName ?? (0, plugins_1.deriveGroupNameFromTarget)(options?.ciTargetName);
|
|
165
165
|
if (disableJestRuntime) {
|
|
166
166
|
const outputs = (target.outputs = getOutputs(projectRoot, rawConfig.coverageDirectory
|
|
167
|
-
? (0,
|
|
167
|
+
? (0, node_path_1.join)(context.workspaceRoot, projectRoot, rawConfig.coverageDirectory)
|
|
168
168
|
: undefined, undefined, context));
|
|
169
169
|
if (options?.ciTargetName) {
|
|
170
170
|
const { specs, testMatch } = await getTestPaths(projectRoot, rawConfig, absConfigFilePath, context, presetCache);
|
|
@@ -177,7 +177,7 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
|
|
|
177
177
|
};
|
|
178
178
|
const specIgnoreRegexes = rawConfig.testPathIgnorePatterns?.map((p) => new RegExp(replaceRootDirInPath(projectRoot, p)));
|
|
179
179
|
for (const testPath of specs) {
|
|
180
|
-
const relativePath = (0, devkit_1.normalizePath)((0,
|
|
180
|
+
const relativePath = (0, devkit_1.normalizePath)((0, node_path_1.relative)((0, node_path_1.join)(context.workspaceRoot, projectRoot), testPath));
|
|
181
181
|
if (relativePath.includes('../')) {
|
|
182
182
|
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' +
|
|
183
183
|
`\n\n${JSON.stringify({
|
|
@@ -249,7 +249,7 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
|
|
|
249
249
|
config = await readConfig({
|
|
250
250
|
_: [],
|
|
251
251
|
$0: undefined,
|
|
252
|
-
}, rawConfig, undefined, (0,
|
|
252
|
+
}, rawConfig, undefined, (0, node_path_1.dirname)(absConfigFilePath));
|
|
253
253
|
}
|
|
254
254
|
catch (e) {
|
|
255
255
|
console.error(e);
|
|
@@ -301,7 +301,7 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
|
|
|
301
301
|
};
|
|
302
302
|
targetGroup.push(options.ciTargetName);
|
|
303
303
|
for (const testPath of testPaths) {
|
|
304
|
-
const relativePath = (0, devkit_1.normalizePath)((0,
|
|
304
|
+
const relativePath = (0, devkit_1.normalizePath)((0, node_path_1.relative)((0, node_path_1.join)(context.workspaceRoot, projectRoot), testPath));
|
|
305
305
|
if (relativePath.includes('../')) {
|
|
306
306
|
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' +
|
|
307
307
|
`\n\n${JSON.stringify({
|
|
@@ -368,17 +368,17 @@ function resolvePresetInputWithoutJestResolver(presetValue, projectRoot, workspa
|
|
|
368
368
|
if (!presetValue)
|
|
369
369
|
return null;
|
|
370
370
|
const presetPath = replaceRootDirInPath(projectRoot, presetValue);
|
|
371
|
-
const isNpmPackage = !presetValue.startsWith('.') && !(0,
|
|
371
|
+
const isNpmPackage = !presetValue.startsWith('.') && !(0, node_path_1.isAbsolute)(presetPath);
|
|
372
372
|
if (isNpmPackage) {
|
|
373
373
|
return { externalDependencies: [presetValue] };
|
|
374
374
|
}
|
|
375
375
|
if (presetPath.startsWith('..')) {
|
|
376
|
-
const relativePath = (0,
|
|
377
|
-
return (0,
|
|
376
|
+
const relativePath = (0, node_path_1.relative)(workspaceRoot, (0, node_path_1.join)(projectRoot, presetPath));
|
|
377
|
+
return (0, node_path_1.join)('{workspaceRoot}', relativePath);
|
|
378
378
|
}
|
|
379
379
|
else {
|
|
380
|
-
const relativePath = (0,
|
|
381
|
-
return (0,
|
|
380
|
+
const relativePath = (0, node_path_1.relative)(projectRoot, presetPath);
|
|
381
|
+
return (0, node_path_1.join)('{projectRoot}', relativePath);
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
384
|
// preset resolution adapted from:
|
|
@@ -387,12 +387,12 @@ function resolvePresetInputWithJestResolver(presetValue, projectRoot, workspaceR
|
|
|
387
387
|
if (!presetValue)
|
|
388
388
|
return null;
|
|
389
389
|
let presetPath = replaceRootDirInPath(projectRoot, presetValue);
|
|
390
|
-
const isNpmPackage = !presetValue.startsWith('.') && !(0,
|
|
390
|
+
const isNpmPackage = !presetValue.startsWith('.') && !(0, node_path_1.isAbsolute)(presetPath);
|
|
391
391
|
presetPath = presetPath.startsWith('.')
|
|
392
392
|
? presetPath
|
|
393
|
-
: (0,
|
|
393
|
+
: (0, node_path_1.join)(presetPath, 'jest-preset');
|
|
394
394
|
const { default: jestResolve } = requireJestUtil('jest-resolve', projectRoot, workspaceRoot);
|
|
395
|
-
const absoluteProjectRoot = (0,
|
|
395
|
+
const absoluteProjectRoot = (0, node_path_1.join)(workspaceRoot, projectRoot);
|
|
396
396
|
const presetModule = jestResolve.findNodeModule(presetPath, {
|
|
397
397
|
basedir: absoluteProjectRoot,
|
|
398
398
|
extensions: ['.json', '.js', '.cjs', '.mjs'],
|
|
@@ -403,26 +403,26 @@ function resolvePresetInputWithJestResolver(presetValue, projectRoot, workspaceR
|
|
|
403
403
|
if (isNpmPackage) {
|
|
404
404
|
return { externalDependencies: [presetValue] };
|
|
405
405
|
}
|
|
406
|
-
const relativePath = (0,
|
|
406
|
+
const relativePath = (0, node_path_1.relative)(absoluteProjectRoot, presetModule);
|
|
407
407
|
return relativePath.startsWith('..')
|
|
408
|
-
? (0,
|
|
409
|
-
: (0,
|
|
408
|
+
? (0, node_path_1.join)('{workspaceRoot}', (0, node_path_1.join)(projectRoot, relativePath))
|
|
409
|
+
: (0, node_path_1.join)('{projectRoot}', relativePath);
|
|
410
410
|
}
|
|
411
411
|
// Adapted from here https://github.com/jestjs/jest/blob/c13bca3/packages/jest-config/src/utils.ts#L57-L69
|
|
412
412
|
function replaceRootDirInPath(rootDir, filePath) {
|
|
413
413
|
if (!filePath.startsWith('<rootDir>')) {
|
|
414
414
|
return filePath;
|
|
415
415
|
}
|
|
416
|
-
return (0,
|
|
416
|
+
return (0, node_path_1.resolve)(rootDir, (0, node_path_1.normalize)(`./${filePath.slice('<rootDir>'.length)}`));
|
|
417
417
|
}
|
|
418
418
|
function getOutputs(projectRoot, coverageDirectory, outputFile, context) {
|
|
419
419
|
function getOutput(path) {
|
|
420
|
-
const relativePath = (0,
|
|
420
|
+
const relativePath = (0, node_path_1.relative)((0, node_path_1.join)(context.workspaceRoot, projectRoot), path);
|
|
421
421
|
if (relativePath.startsWith('..')) {
|
|
422
|
-
return (0,
|
|
422
|
+
return (0, node_path_1.join)('{workspaceRoot}', (0, node_path_1.join)(projectRoot, relativePath));
|
|
423
423
|
}
|
|
424
424
|
else {
|
|
425
|
-
return (0,
|
|
425
|
+
return (0, node_path_1.join)('{projectRoot}', relativePath);
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
428
|
const outputs = [];
|
|
@@ -459,11 +459,11 @@ function requireJestUtil(packageName, projectRoot, workspaceRoot) {
|
|
|
459
459
|
if (!resolvedJestCorePaths[jestPath]) {
|
|
460
460
|
// nx-ignore-next-line
|
|
461
461
|
resolvedJestCorePaths[jestPath] = require.resolve('@jest/core', {
|
|
462
|
-
paths: [(0,
|
|
462
|
+
paths: [(0, node_path_1.dirname)(jestPath)],
|
|
463
463
|
});
|
|
464
464
|
}
|
|
465
465
|
return require(require.resolve(packageName, {
|
|
466
|
-
paths: [(0,
|
|
466
|
+
paths: [(0, node_path_1.dirname)(resolvedJestCorePaths[jestPath])],
|
|
467
467
|
}));
|
|
468
468
|
}
|
|
469
469
|
async function getTestPaths(projectRoot, rawConfig, absConfigFilePath, context, presetCache) {
|
|
@@ -472,7 +472,7 @@ async function getTestPaths(projectRoot, rawConfig, absConfigFilePath, context,
|
|
|
472
472
|
// Default copied from https://github.com/jestjs/jest/blob/d1a2ed7/packages/jest-config/src/Defaults.ts#L84
|
|
473
473
|
'**/__tests__/**/*.?([mc])[jt]s?(x)',
|
|
474
474
|
'**/?(*.)+(spec|test).?([mc])[jt]s?(x)',
|
|
475
|
-
]).map((pattern) => (0,
|
|
475
|
+
]).map((pattern) => (0, node_path_1.join)(projectRoot, pattern)), []);
|
|
476
476
|
const testRegex = await getJestOption(rawConfig, absConfigFilePath, 'testRegex', presetCache);
|
|
477
477
|
if (testRegex) {
|
|
478
478
|
const testRegexes = Array.isArray(rawConfig.testRegex)
|
|
@@ -486,8 +486,8 @@ async function getJestOption(rawConfig, absConfigFilePath, optionName, presetCac
|
|
|
486
486
|
if (rawConfig[optionName])
|
|
487
487
|
return rawConfig[optionName];
|
|
488
488
|
if (rawConfig.preset) {
|
|
489
|
-
const dir = (0,
|
|
490
|
-
const presetPath = (0,
|
|
489
|
+
const dir = (0, node_path_1.dirname)(absConfigFilePath);
|
|
490
|
+
const presetPath = (0, node_path_1.resolve)(dir, rawConfig.preset);
|
|
491
491
|
try {
|
|
492
492
|
let preset = presetCache[presetPath];
|
|
493
493
|
if (!preset) {
|
|
@@ -506,24 +506,3 @@ async function getJestOption(rawConfig, absConfigFilePath, optionName, presetCac
|
|
|
506
506
|
}
|
|
507
507
|
return undefined;
|
|
508
508
|
}
|
|
509
|
-
/**
|
|
510
|
-
* Helper that tries to deduct the name of the CI group, based on the related target name.
|
|
511
|
-
*
|
|
512
|
-
* This will work well, when the CI target name follows the documented naming convention or similar (for e.g `test-ci`, `e2e-ci`, `ny-e2e-ci`, etc).
|
|
513
|
-
*
|
|
514
|
-
* For example, `test-ci` => `TEST (CI)`, `e2e-ci` => `E2E (CI)`, `my-e2e-ci` => `MY E2E (CI)`
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
* @param ciTargetName name of the CI target
|
|
518
|
-
* @returns the deducted group name or `${ciTargetName.toUpperCase()} (CI)` if cannot be deducted automatically
|
|
519
|
-
*/
|
|
520
|
-
function deductGroupNameFromTarget(ciTargetName) {
|
|
521
|
-
if (!ciTargetName) {
|
|
522
|
-
return null;
|
|
523
|
-
}
|
|
524
|
-
const parts = ciTargetName.split('-').map((v) => v.toUpperCase());
|
|
525
|
-
if (parts.length > 1) {
|
|
526
|
-
return `${parts.slice(0, -1).join(' ')} (${parts[parts.length - 1]})`;
|
|
527
|
-
}
|
|
528
|
-
return `${parts[0]} (CI)`; // default group name when there is a single segment
|
|
529
|
-
}
|