@nx/vitest 23.0.0-beta.12 → 23.0.0-beta.14
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/executors/test/vitest.impl.js +1 -1
- package/src/generators/configuration/configuration.d.ts.map +1 -1
- package/src/generators/configuration/configuration.js +21 -12
- package/src/generators/init/init.d.ts.map +1 -1
- package/src/generators/init/init.js +13 -8
- package/src/plugins/plugin.js +6 -2
- package/src/utils/generator-utils.js +2 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vitest",
|
|
3
3
|
"description": "The Nx Plugin for Vitest to enable fast unit testing with Vitest.",
|
|
4
|
-
"version": "23.0.0-beta.
|
|
4
|
+
"version": "23.0.0-beta.14",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
"executors": "./executors.json",
|
|
53
53
|
"generators": "./generators.json",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@nx/devkit": "23.0.0-beta.
|
|
56
|
-
"@nx/js": "23.0.0-beta.
|
|
55
|
+
"@nx/devkit": "23.0.0-beta.14",
|
|
56
|
+
"@nx/js": "23.0.0-beta.14",
|
|
57
57
|
"tslib": "^2.3.0",
|
|
58
58
|
"semver": "^7.6.3",
|
|
59
59
|
"@phenomnomnominal/tsquery": "~6.2.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@nx/eslint": "23.0.0-beta.
|
|
62
|
+
"@nx/eslint": "23.0.0-beta.14",
|
|
63
63
|
"vitest": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0",
|
|
64
64
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
65
65
|
},
|
|
@@ -75,6 +75,6 @@
|
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"nx": "23.0.0-beta.
|
|
78
|
+
"nx": "23.0.0-beta.14"
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.vitestExecutor = vitestExecutor;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const internal_1 = require("@nx/js/
|
|
6
|
+
const internal_1 = require("@nx/js/internal");
|
|
7
7
|
const nx_reporter_1 = require("./lib/nx-reporter");
|
|
8
8
|
const utils_1 = require("./lib/utils");
|
|
9
9
|
const executor_utils_1 = require("../../utils/executor-utils");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/generators/configuration/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/generators/configuration/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EAWjB,IAAI,EAGL,MAAM,YAAY,CAAC;AAepB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAmCjD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,8BAOlB;AAED,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,8BAkNlB;AAuPD,eAAe,sBAAsB,CAAC"}
|
|
@@ -4,9 +4,9 @@ exports.configurationGenerator = configurationGenerator;
|
|
|
4
4
|
exports.configurationGeneratorInternal = configurationGeneratorInternal;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
7
8
|
const js_1 = require("@nx/js");
|
|
8
|
-
const
|
|
9
|
-
const versions_1 = require("@nx/js/src/utils/versions");
|
|
9
|
+
const internal_2 = require("@nx/js/internal");
|
|
10
10
|
const path_1 = require("path");
|
|
11
11
|
const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
|
|
12
12
|
const generator_utils_1 = require("../../utils/generator-utils");
|
|
@@ -123,7 +123,7 @@ getTestBed().initTestEnvironment(
|
|
|
123
123
|
else if (uiFramework === 'react') {
|
|
124
124
|
(0, generator_utils_1.createOrEditViteConfig)(tree, {
|
|
125
125
|
project: schema.project,
|
|
126
|
-
includeLib: (0,
|
|
126
|
+
includeLib: (0, internal_2.getProjectType)(tree, root, projectType) === 'library',
|
|
127
127
|
includeVitest: true,
|
|
128
128
|
inSourceTests: schema.inSourceTests,
|
|
129
129
|
rollupOptionsExternal: [
|
|
@@ -146,7 +146,7 @@ getTestBed().initTestEnvironment(
|
|
|
146
146
|
(0, generator_utils_1.createOrEditViteConfig)(tree, {
|
|
147
147
|
...schema,
|
|
148
148
|
includeVitest: true,
|
|
149
|
-
includeLib: (0,
|
|
149
|
+
includeLib: (0, internal_2.getProjectType)(tree, root, projectType) === 'library',
|
|
150
150
|
useEsmExtension: true,
|
|
151
151
|
}, true, {
|
|
152
152
|
vitestFileName: useVitestConfig,
|
|
@@ -154,22 +154,21 @@ getTestBed().initTestEnvironment(
|
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
const isTsSolutionSetup = (0,
|
|
157
|
+
const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)(tree);
|
|
158
158
|
createFiles(tree, schema, root, isTsSolutionSetup);
|
|
159
159
|
updateTsConfig(tree, schema, root, projectType);
|
|
160
160
|
if (isTsSolutionSetup) {
|
|
161
161
|
// in the TS solution setup, the test target depends on the build outputs
|
|
162
162
|
// so we need to setup the task pipeline accordingly
|
|
163
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
163
|
+
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
|
|
164
164
|
const testTarget = schema.testTarget ?? 'test';
|
|
165
|
-
nxJson.targetDefaults
|
|
166
|
-
|
|
167
|
-
nxJson
|
|
168
|
-
nxJson.targetDefaults[testTarget].dependsOn = Array.from(new Set([...nxJson.targetDefaults[testTarget].dependsOn, '^build']));
|
|
165
|
+
const existing = findTestDefault(nxJson.targetDefaults, testTarget);
|
|
166
|
+
const dependsOn = Array.from(new Set([...(existing?.dependsOn ?? []), '^build']));
|
|
167
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, { target: testTarget, dependsOn });
|
|
169
168
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
170
169
|
}
|
|
171
170
|
const devDependencies = await getCoverageProviderDependency(tree, schema.coverageProvider);
|
|
172
|
-
devDependencies['@types/node'] =
|
|
171
|
+
devDependencies['@types/node'] = internal_2.typesNodeVersion;
|
|
173
172
|
if (!schema.skipPackageJson) {
|
|
174
173
|
const installDependenciesTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, true);
|
|
175
174
|
tasks.push(installDependenciesTask);
|
|
@@ -231,7 +230,7 @@ function updateTsConfig(tree, options, projectRoot, projectType) {
|
|
|
231
230
|
return json;
|
|
232
231
|
});
|
|
233
232
|
}
|
|
234
|
-
let runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, (0,
|
|
233
|
+
let runtimeTsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, (0, internal_2.getProjectType)(tree, projectRoot, projectType) === 'application'
|
|
235
234
|
? 'tsconfig.app.json'
|
|
236
235
|
: 'tsconfig.lib.json');
|
|
237
236
|
if (options.runtimeTsconfigFileName) {
|
|
@@ -354,4 +353,14 @@ function findBuildTarget(project) {
|
|
|
354
353
|
}
|
|
355
354
|
return project.targets?.build ?? null;
|
|
356
355
|
}
|
|
356
|
+
function findTestDefault(td, target) {
|
|
357
|
+
if (!td)
|
|
358
|
+
return undefined;
|
|
359
|
+
if (Array.isArray(td)) {
|
|
360
|
+
return td.find((e) => e.target === target &&
|
|
361
|
+
e.projects === undefined &&
|
|
362
|
+
e.plugin === undefined);
|
|
363
|
+
}
|
|
364
|
+
return td[target];
|
|
365
|
+
}
|
|
357
366
|
exports.default = configurationGenerator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/generators/init/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/generators/init/init.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,IAAI,EACT,KAAK,iBAAiB,EAOvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAa/C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,qBA2BzE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,QAoC9C;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,8BAkC1E;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -29,7 +29,7 @@ function updateDependencies(tree, schema) {
|
|
|
29
29
|
}, undefined, schema.keepExistingVersions);
|
|
30
30
|
}
|
|
31
31
|
function updateNxJsonSettings(tree) {
|
|
32
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
32
|
+
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
|
|
33
33
|
const productionFileSet = nxJson.namedInputs?.production;
|
|
34
34
|
if (productionFileSet) {
|
|
35
35
|
productionFileSet.push('!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)', '!{projectRoot}/tsconfig.spec.json');
|
|
@@ -37,13 +37,18 @@ function updateNxJsonSettings(tree) {
|
|
|
37
37
|
}
|
|
38
38
|
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string' ? p === '@nx/vitest' : p.plugin === '@nx/vitest');
|
|
39
39
|
if (!hasPlugin) {
|
|
40
|
-
nxJson.targetDefaults
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
const existing = (0, internal_1.normalizeTargetDefaults)(nxJson.targetDefaults).find((e) => e.executor === '@nx/vitest:test' &&
|
|
41
|
+
e.target === undefined &&
|
|
42
|
+
e.projects === undefined &&
|
|
43
|
+
e.plugin === undefined);
|
|
44
|
+
(0, internal_1.upsertTargetDefault)(tree, nxJson, {
|
|
45
|
+
executor: '@nx/vitest:test',
|
|
46
|
+
cache: existing?.cache ?? true,
|
|
47
|
+
inputs: existing?.inputs ?? [
|
|
48
|
+
'default',
|
|
49
|
+
productionFileSet ? '^production' : '^default',
|
|
50
|
+
],
|
|
51
|
+
});
|
|
47
52
|
}
|
|
48
53
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
49
54
|
}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -37,7 +37,7 @@ exports.createNodesV2 = exports.createNodes = exports.createDependencies = void
|
|
|
37
37
|
const internal_1 = require("@nx/devkit/internal");
|
|
38
38
|
const devkit_1 = require("@nx/devkit");
|
|
39
39
|
const js_1 = require("@nx/js");
|
|
40
|
-
const internal_2 = require("@nx/js/
|
|
40
|
+
const internal_2 = require("@nx/js/internal");
|
|
41
41
|
const node_fs_1 = require("node:fs");
|
|
42
42
|
const node_path_1 = require("node:path");
|
|
43
43
|
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
|
@@ -417,7 +417,11 @@ async function getTestPathsRelativeToProjectRoot(projectRoot, workspaceRoot) {
|
|
|
417
417
|
watch: false,
|
|
418
418
|
});
|
|
419
419
|
const relevantTestSpecifications = await vitest.getRelevantTestSpecifications();
|
|
420
|
+
// Sort to keep atomized target name insertion order stable.
|
|
421
|
+
// vitest.getRelevantTestSpecifications uses tinyglobby internally,
|
|
422
|
+
// which does not sort its filesystem traversal output.
|
|
420
423
|
return relevantTestSpecifications
|
|
421
424
|
.filter((ts) => fullProjectRoot === '.' ? true : ts.moduleId.startsWith(fullProjectRoot))
|
|
422
|
-
.map((ts) => (0, devkit_1.normalizePath)((0, node_path_1.relative)(projectRoot, ts.moduleId)))
|
|
425
|
+
.map((ts) => (0, devkit_1.normalizePath)((0, node_path_1.relative)(projectRoot, ts.moduleId)))
|
|
426
|
+
.sort();
|
|
423
427
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.addOrChangeTestTarget = addOrChangeTestTarget;
|
|
4
4
|
exports.createOrEditViteConfig = createOrEditViteConfig;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const
|
|
6
|
+
const internal_1 = require("@nx/js/internal");
|
|
7
7
|
const vite_config_edit_utils_1 = require("./vite-config-edit-utils");
|
|
8
8
|
const deprecation_1 = require("./deprecation");
|
|
9
9
|
const versions_1 = require("./versions");
|
|
@@ -41,7 +41,7 @@ function createOrEditViteConfig(tree, options, onlyVitest, extraOptions = {}) {
|
|
|
41
41
|
const viteConfigPath = extraOptions.vitestFileName
|
|
42
42
|
? `${projectRoot}/vitest.config.${extension}`
|
|
43
43
|
: `${projectRoot}/vite.config.${extension}`;
|
|
44
|
-
const isTsSolutionSetup = (0,
|
|
44
|
+
const isTsSolutionSetup = (0, internal_1.isUsingTsSolutionSetup)(tree);
|
|
45
45
|
const buildOutDir = isTsSolutionSetup
|
|
46
46
|
? './dist'
|
|
47
47
|
: projectRoot === '.'
|