@nx/jest 19.2.0-beta.4 → 19.2.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 +4 -4
- package/plugin.d.ts +1 -1
- package/plugin.js +2 -2
- package/src/generators/init/init.js +1 -1
- package/src/plugins/plugin.d.ts +6 -2
- package/src/plugins/plugin.js +64 -51
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "19.2.0-beta.
|
|
3
|
+
"version": "19.2.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": {
|
|
@@ -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": "19.2.0-beta.
|
|
41
|
-
"@nx/js": "19.2.0-beta.
|
|
40
|
+
"@nx/devkit": "19.2.0-beta.6",
|
|
41
|
+
"@nx/js": "19.2.0-beta.6",
|
|
42
42
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
43
43
|
"chalk": "^4.1.0",
|
|
44
44
|
"identity-obj-proxy": "3.0.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"resolve.exports": "1.1.0",
|
|
50
50
|
"tslib": "^2.3.0",
|
|
51
51
|
"yargs-parser": "21.1.1",
|
|
52
|
-
"@nrwl/jest": "19.2.0-beta.
|
|
52
|
+
"@nrwl/jest": "19.2.0-beta.6"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
package/plugin.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createNodes,
|
|
1
|
+
export { createNodes, createNodesV2, JestPluginOptions, } from './src/plugins/plugin';
|
package/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createNodesV2 = exports.createNodes = void 0;
|
|
4
4
|
var plugin_1 = require("./src/plugins/plugin");
|
|
5
5
|
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
|
|
@@ -68,7 +68,7 @@ async function jestInitGeneratorInternal(tree, options) {
|
|
|
68
68
|
if (!tree.exists(`jest.preset.${presetExt}`)) {
|
|
69
69
|
updateProductionFileSet(tree);
|
|
70
70
|
if (options.addPlugin) {
|
|
71
|
-
await (0, add_plugin_1.
|
|
71
|
+
await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/jest/plugin', plugin_1.createNodesV2, {
|
|
72
72
|
targetName: ['test', 'jest:test', 'jest-test'],
|
|
73
73
|
}, options.updatePackageScripts);
|
|
74
74
|
}
|
package/src/plugins/plugin.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateNodes, CreateNodesV2 } from '@nx/devkit';
|
|
2
2
|
export interface JestPluginOptions {
|
|
3
3
|
targetName?: string;
|
|
4
4
|
ciTargetName?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const createNodesV2: CreateNodesV2<JestPluginOptions>;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated This is replaced with {@link createNodesV2}. Update your plugin to export its own `createNodesV2` function that wraps this one instead.
|
|
9
|
+
* This function will change to the v2 function in Nx 20.
|
|
10
|
+
*/
|
|
7
11
|
export declare const createNodes: CreateNodes<JestPluginOptions>;
|
package/src/plugins/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = exports.
|
|
3
|
+
exports.createNodes = exports.createNodesV2 = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
@@ -12,64 +12,77 @@ const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
|
|
12
12
|
const package_json_workspaces_1 = require("nx/src/plugins/package-json-workspaces");
|
|
13
13
|
const globs_1 = require("nx/src/utils/globs");
|
|
14
14
|
const minimatch_1 = require("minimatch");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
function readTargetsCache() {
|
|
15
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
16
|
+
function readTargetsCache(cachePath) {
|
|
18
17
|
return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
|
19
18
|
}
|
|
20
|
-
function writeTargetsToCache() {
|
|
21
|
-
|
|
22
|
-
(0, devkit_1.writeJsonFile)(cachePath, {
|
|
23
|
-
...cache,
|
|
24
|
-
...targetsCache,
|
|
25
|
-
});
|
|
19
|
+
function writeTargetsToCache(cachePath, results) {
|
|
20
|
+
(0, devkit_1.writeJsonFile)(cachePath, results);
|
|
26
21
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const packageManagerWorkspacesGlob = (0, globs_1.combineGlobPatterns)((0, package_json_workspaces_1.getGlobPatternsFromPackageManagerWorkspaces)(context.workspaceRoot));
|
|
37
|
-
// Do not create a project if package.json and project.json isn't there.
|
|
38
|
-
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
39
|
-
if (!siblingFiles.includes('package.json') &&
|
|
40
|
-
!siblingFiles.includes('project.json')) {
|
|
41
|
-
return {};
|
|
22
|
+
const jestConfigGlob = '**/jest.config.{cjs,mjs,js,cts,mts,ts}';
|
|
23
|
+
exports.createNodesV2 = [
|
|
24
|
+
jestConfigGlob,
|
|
25
|
+
async (configFiles, options, context) => {
|
|
26
|
+
const optionsHash = (0, devkit_internals_1.hashObject)(options);
|
|
27
|
+
const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, `jest-${optionsHash}.hash`);
|
|
28
|
+
const targetsCache = readTargetsCache(cachePath);
|
|
29
|
+
try {
|
|
30
|
+
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache), configFiles, options, context);
|
|
42
31
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const path = (0, devkit_1.joinPathFragments)(projectRoot, 'package.json');
|
|
46
|
-
const isPackageJsonProject = (0, minimatch_1.minimatch)(path, packageManagerWorkspacesGlob);
|
|
47
|
-
if (!isPackageJsonProject) {
|
|
48
|
-
return {};
|
|
49
|
-
}
|
|
32
|
+
finally {
|
|
33
|
+
writeTargetsToCache(cachePath, targetsCache);
|
|
50
34
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated This is replaced with {@link createNodesV2}. Update your plugin to export its own `createNodesV2` function that wraps this one instead.
|
|
39
|
+
* This function will change to the v2 function in Nx 20.
|
|
40
|
+
*/
|
|
41
|
+
exports.createNodes = [
|
|
42
|
+
jestConfigGlob,
|
|
43
|
+
(...args) => {
|
|
44
|
+
devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
|
|
45
|
+
return createNodesInternal(...args, {});
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
async function createNodesInternal(configFilePath, options, context, targetsCache) {
|
|
49
|
+
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
50
|
+
const packageManagerWorkspacesGlob = (0, globs_1.combineGlobPatterns)((0, package_json_workspaces_1.getGlobPatternsFromPackageManagerWorkspaces)(context.workspaceRoot));
|
|
51
|
+
// Do not create a project if package.json and project.json isn't there.
|
|
52
|
+
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
53
|
+
if (!siblingFiles.includes('package.json') &&
|
|
54
|
+
!siblingFiles.includes('project.json')) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
else if (!siblingFiles.includes('project.json') &&
|
|
58
|
+
siblingFiles.includes('package.json')) {
|
|
59
|
+
const path = (0, devkit_1.joinPathFragments)(projectRoot, 'package.json');
|
|
60
|
+
const isPackageJsonProject = (0, minimatch_1.minimatch)(path, packageManagerWorkspacesGlob);
|
|
61
|
+
if (!isPackageJsonProject) {
|
|
56
62
|
return {};
|
|
57
63
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
}
|
|
65
|
+
const jestConfigContent = (0, fs_1.readFileSync)((0, path_1.resolve)(context.workspaceRoot, configFilePath), 'utf-8');
|
|
66
|
+
if (jestConfigContent.includes('getJestProjectsAsync()')) {
|
|
67
|
+
// The `getJestProjectsAsync` function uses the project graph, which leads to a
|
|
68
|
+
// circular dependency. We can skip this since it's no intended to be used for
|
|
69
|
+
// an Nx project.
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
options = normalizeOptions(options);
|
|
73
|
+
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context);
|
|
74
|
+
targetsCache[hash] ??= await buildJestTargets(configFilePath, projectRoot, options, context);
|
|
75
|
+
const { targets, metadata } = targetsCache[hash];
|
|
76
|
+
return {
|
|
77
|
+
projects: {
|
|
78
|
+
[projectRoot]: {
|
|
79
|
+
root: projectRoot,
|
|
80
|
+
targets,
|
|
81
|
+
metadata,
|
|
69
82
|
},
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
73
86
|
async function buildJestTargets(configFilePath, projectRoot, options, context) {
|
|
74
87
|
const absConfigFilePath = (0, path_1.resolve)(context.workspaceRoot, configFilePath);
|
|
75
88
|
if (require.cache[absConfigFilePath]) {
|