@nx/jest 17.0.4 → 17.0.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/LICENSE +1 -1
- package/README.md +4 -9
- package/generators.json +2 -2
- package/index.d.ts +1 -1
- package/index.js +1 -2
- package/migrations.json +0 -14
- package/package.json +4 -6
- package/src/generators/configuration/configuration.d.ts +0 -1
- package/src/generators/configuration/configuration.js +7 -42
- package/src/generators/configuration/files/jest.config.ts__tmpl__ +1 -1
- package/src/generators/configuration/files-angular/jest.config.ts__tmpl__ +1 -1
- package/src/generators/configuration/lib/create-files.d.ts +1 -1
- package/src/generators/configuration/lib/create-files.js +1 -2
- package/src/generators/configuration/lib/update-jestconfig.js +1 -6
- package/src/generators/configuration/lib/update-workspace.js +8 -1
- package/src/generators/configuration/schema.d.ts +0 -8
- package/src/generators/configuration/schema.json +1 -1
- package/src/generators/init/init.d.ts +3 -4
- package/src/generators/init/init.js +130 -66
- package/src/generators/init/schema.d.ts +8 -5
- package/src/generators/init/schema.json +20 -13
- package/src/utils/config/find-root-jest-files.js +0 -3
- package/src/utils/config/get-jest-projects.d.ts +1 -16
- package/src/utils/config/get-jest-projects.js +3 -98
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/plugin.d.ts +0 -1
- package/plugin.js +0 -6
- package/src/generators/configuration/lib/create-jest-config.d.ts +0 -3
- package/src/generators/configuration/lib/create-jest-config.js +0 -102
- package/src/generators/configuration/lib/ensure-dependencies.d.ts +0 -3
- package/src/generators/configuration/lib/ensure-dependencies.js +0 -34
- package/src/generators/configuration/lib/update-vscode-recommended-extensions.d.ts +0 -2
- package/src/generators/configuration/lib/update-vscode-recommended-extensions.js +0 -18
- package/src/migrations/update-17-1-0/move-options-to-target-defaults.d.ts +0 -2
- package/src/migrations/update-17-1-0/move-options-to-target-defaults.js +0 -117
- package/src/plugins/plugin.d.ts +0 -6
- package/src/plugins/plugin.js +0 -130
- package/src/utils/config/is-preset-cjs.d.ts +0 -2
- package/src/utils/config/is-preset-cjs.js +0 -15
package/src/plugins/plugin.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = exports.createDependencies = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
|
|
7
|
-
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const jest_config_1 = require("jest-config");
|
|
10
|
-
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
11
|
-
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
12
|
-
const package_json_workspaces_1 = require("nx/src/plugins/package-json-workspaces");
|
|
13
|
-
const globs_1 = require("nx/src/utils/globs");
|
|
14
|
-
const minimatch_1 = require("minimatch");
|
|
15
|
-
const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'jest.hash');
|
|
16
|
-
const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
|
|
17
|
-
const calculatedTargets = {};
|
|
18
|
-
function readTargetsCache() {
|
|
19
|
-
return (0, devkit_1.readJsonFile)(cachePath);
|
|
20
|
-
}
|
|
21
|
-
function writeTargetsToCache(targets) {
|
|
22
|
-
(0, devkit_1.writeJsonFile)(cachePath, targets);
|
|
23
|
-
}
|
|
24
|
-
const createDependencies = () => {
|
|
25
|
-
writeTargetsToCache(calculatedTargets);
|
|
26
|
-
return [];
|
|
27
|
-
};
|
|
28
|
-
exports.createDependencies = createDependencies;
|
|
29
|
-
exports.createNodes = [
|
|
30
|
-
'**/jest.config.{cjs,mjs,js,cts,mts,ts}',
|
|
31
|
-
async (configFilePath, options, context) => {
|
|
32
|
-
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
33
|
-
const packageManagerWorkspacesGlob = (0, globs_1.combineGlobPatterns)((0, package_json_workspaces_1.getGlobPatternsFromPackageManagerWorkspaces)(context.workspaceRoot));
|
|
34
|
-
// Do not create a project if package.json and project.json isn't there.
|
|
35
|
-
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
36
|
-
if (!siblingFiles.includes('package.json') &&
|
|
37
|
-
!siblingFiles.includes('project.json')) {
|
|
38
|
-
return {};
|
|
39
|
-
}
|
|
40
|
-
else if (!siblingFiles.includes('project.json') &&
|
|
41
|
-
siblingFiles.includes('package.json')) {
|
|
42
|
-
const path = (0, devkit_1.joinPathFragments)(projectRoot, 'package.json');
|
|
43
|
-
const isPackageJsonProject = (0, minimatch_1.minimatch)(path, packageManagerWorkspacesGlob);
|
|
44
|
-
if (!isPackageJsonProject) {
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const jestConfigContent = (0, fs_1.readFileSync)((0, path_1.resolve)(context.workspaceRoot, configFilePath), 'utf-8');
|
|
49
|
-
if (jestConfigContent.includes('getJestProjectsAsync()')) {
|
|
50
|
-
// The `getJestProjectsAsync` function uses the project graph, which leads to a
|
|
51
|
-
// circular dependency. We can skip this since it's no intended to be used for
|
|
52
|
-
// an Nx project.
|
|
53
|
-
return {};
|
|
54
|
-
}
|
|
55
|
-
options = normalizeOptions(options);
|
|
56
|
-
const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context);
|
|
57
|
-
const targets = targetsCache[hash] ??
|
|
58
|
-
(await buildJestTargets(configFilePath, projectRoot, options, context));
|
|
59
|
-
calculatedTargets[hash] = targets;
|
|
60
|
-
return {
|
|
61
|
-
projects: {
|
|
62
|
-
[projectRoot]: {
|
|
63
|
-
root: projectRoot,
|
|
64
|
-
targets: targets,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
];
|
|
70
|
-
async function buildJestTargets(configFilePath, projectRoot, options, context) {
|
|
71
|
-
const config = await (0, jest_config_1.readConfig)({
|
|
72
|
-
_: [],
|
|
73
|
-
$0: undefined,
|
|
74
|
-
}, (0, path_1.resolve)(context.workspaceRoot, configFilePath));
|
|
75
|
-
const targetDefaults = (0, project_configuration_utils_1.readTargetDefaultsForTarget)(options.targetName, context.nxJsonConfiguration.targetDefaults, 'nx:run-commands');
|
|
76
|
-
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
77
|
-
const targets = {};
|
|
78
|
-
const target = (targets[options.targetName] = {
|
|
79
|
-
command: 'jest',
|
|
80
|
-
options: {
|
|
81
|
-
cwd: projectRoot,
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
if (!targetDefaults?.cache) {
|
|
85
|
-
target.cache = true;
|
|
86
|
-
}
|
|
87
|
-
if (!targetDefaults?.inputs) {
|
|
88
|
-
target.inputs = getInputs(namedInputs);
|
|
89
|
-
}
|
|
90
|
-
if (!targetDefaults?.outputs) {
|
|
91
|
-
target.outputs = getOutputs(projectRoot, config, context);
|
|
92
|
-
}
|
|
93
|
-
return targets;
|
|
94
|
-
}
|
|
95
|
-
function getInputs(namedInputs) {
|
|
96
|
-
return [
|
|
97
|
-
...('production' in namedInputs
|
|
98
|
-
? ['default', '^production']
|
|
99
|
-
: ['default', '^default']),
|
|
100
|
-
{
|
|
101
|
-
externalDependencies: ['jest'],
|
|
102
|
-
},
|
|
103
|
-
];
|
|
104
|
-
}
|
|
105
|
-
function getOutputs(projectRoot, { globalConfig }, context) {
|
|
106
|
-
function getOutput(path) {
|
|
107
|
-
const relativePath = (0, path_1.relative)((0, path_1.join)(context.workspaceRoot, projectRoot), path);
|
|
108
|
-
if (relativePath.startsWith('..')) {
|
|
109
|
-
return (0, path_1.join)('{workspaceRoot}', (0, path_1.join)(projectRoot, relativePath));
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
return (0, path_1.join)('{projectRoot}', relativePath);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
const outputs = [];
|
|
116
|
-
for (const outputOption of [
|
|
117
|
-
globalConfig.coverageDirectory,
|
|
118
|
-
globalConfig.outputFile,
|
|
119
|
-
]) {
|
|
120
|
-
if (outputOption) {
|
|
121
|
-
outputs.push(getOutput(outputOption));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return outputs;
|
|
125
|
-
}
|
|
126
|
-
function normalizeOptions(options) {
|
|
127
|
-
options ??= {};
|
|
128
|
-
options.targetName ??= 'test';
|
|
129
|
-
return options;
|
|
130
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPresetCjs = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
function isPresetCjs(tree) {
|
|
6
|
-
if (tree.exists('jest.preset.cjs')) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
const rootPkgJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
10
|
-
if (rootPkgJson.type && rootPkgJson.type === 'module') {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
exports.isPresetCjs = isPresetCjs;
|