@nx/jest 19.2.3 → 19.3.0-beta.1
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/src/plugins/plugin.js +45 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.3.0-beta.1",
|
|
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.
|
|
41
|
-
"@nx/js": "19.
|
|
40
|
+
"@nx/devkit": "19.3.0-beta.1",
|
|
41
|
+
"@nx/js": "19.3.0-beta.1",
|
|
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.
|
|
52
|
+
"@nrwl/jest": "19.3.0-beta.1"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
package/src/plugins/plugin.js
CHANGED
|
@@ -6,6 +6,7 @@ const path_1 = require("path");
|
|
|
6
6
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const jest_config_1 = require("jest-config");
|
|
9
|
+
const jest_resolve_1 = require("jest-resolve");
|
|
9
10
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
10
11
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
11
12
|
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
|
@@ -88,10 +89,11 @@ async function buildJestTargets(configFilePath, projectRoot, options, context) {
|
|
|
88
89
|
if (require.cache[absConfigFilePath]) {
|
|
89
90
|
(0, config_utils_1.clearRequireCache)();
|
|
90
91
|
}
|
|
92
|
+
const rawConfig = await (0, config_utils_1.loadConfigFile)(absConfigFilePath);
|
|
91
93
|
const config = await (0, jest_config_1.readConfig)({
|
|
92
94
|
_: [],
|
|
93
95
|
$0: undefined,
|
|
94
|
-
}, absConfigFilePath);
|
|
96
|
+
}, rawConfig, undefined, (0, path_1.dirname)(absConfigFilePath));
|
|
95
97
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
96
98
|
const targets = {};
|
|
97
99
|
const target = (targets[options.targetName] = {
|
|
@@ -105,7 +107,7 @@ async function buildJestTargets(configFilePath, projectRoot, options, context) {
|
|
|
105
107
|
},
|
|
106
108
|
});
|
|
107
109
|
const cache = (target.cache = true);
|
|
108
|
-
const inputs = (target.inputs = getInputs(namedInputs));
|
|
110
|
+
const inputs = (target.inputs = getInputs(namedInputs, rawConfig, projectRoot, context.workspaceRoot));
|
|
109
111
|
const outputs = (target.outputs = getOutputs(projectRoot, config, context));
|
|
110
112
|
let metadata;
|
|
111
113
|
if (options?.ciTargetName) {
|
|
@@ -168,15 +170,51 @@ async function buildJestTargets(configFilePath, projectRoot, options, context) {
|
|
|
168
170
|
}
|
|
169
171
|
return { targets, metadata };
|
|
170
172
|
}
|
|
171
|
-
function getInputs(namedInputs) {
|
|
172
|
-
|
|
173
|
+
function getInputs(namedInputs, jestConfig, projectRoot, workspaceRoot) {
|
|
174
|
+
const inputs = [
|
|
173
175
|
...('production' in namedInputs
|
|
174
176
|
? ['default', '^production']
|
|
175
177
|
: ['default', '^default']),
|
|
176
|
-
{
|
|
177
|
-
externalDependencies: ['jest'],
|
|
178
|
-
},
|
|
179
178
|
];
|
|
179
|
+
const externalDependencies = ['jest'];
|
|
180
|
+
const presetInput = resolvePresetInput(jestConfig.preset, projectRoot, workspaceRoot);
|
|
181
|
+
if (presetInput) {
|
|
182
|
+
if (typeof presetInput !== 'string' &&
|
|
183
|
+
'externalDependencies' in presetInput) {
|
|
184
|
+
externalDependencies.push(...presetInput.externalDependencies);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
inputs.push(presetInput);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
inputs.push({ externalDependencies });
|
|
191
|
+
return inputs;
|
|
192
|
+
}
|
|
193
|
+
// preset resolution adapted from:
|
|
194
|
+
// https://github.com/jestjs/jest/blob/c54bccd657fb4cf060898717c09f633b4da3eec4/packages/jest-config/src/normalize.ts#L122
|
|
195
|
+
function resolvePresetInput(presetValue, projectRoot, workspaceRoot) {
|
|
196
|
+
if (!presetValue) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
let presetPath = (0, jest_config_1.replaceRootDirInPath)(projectRoot, presetValue);
|
|
200
|
+
const isNpmPackage = !presetValue.startsWith('.') && !(0, path_1.isAbsolute)(presetPath);
|
|
201
|
+
presetPath = presetPath.startsWith('.')
|
|
202
|
+
? presetPath
|
|
203
|
+
: (0, path_1.join)(presetPath, 'jest-preset');
|
|
204
|
+
const presetModule = jest_resolve_1.default.findNodeModule(presetPath, {
|
|
205
|
+
basedir: projectRoot,
|
|
206
|
+
extensions: ['.json', '.js', '.cjs', '.mjs'],
|
|
207
|
+
});
|
|
208
|
+
if (!presetModule) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
if (isNpmPackage) {
|
|
212
|
+
return { externalDependencies: [presetValue] };
|
|
213
|
+
}
|
|
214
|
+
const relativePath = (0, path_1.relative)((0, path_1.join)(workspaceRoot, projectRoot), presetModule);
|
|
215
|
+
return relativePath.startsWith('..')
|
|
216
|
+
? (0, path_1.join)('{workspaceRoot}', (0, path_1.join)(projectRoot, relativePath))
|
|
217
|
+
: (0, path_1.join)('{projectRoot}', relativePath);
|
|
180
218
|
}
|
|
181
219
|
function getOutputs(projectRoot, { globalConfig }, context) {
|
|
182
220
|
function getOutput(path) {
|