@nx/vitest 22.6.0-beta.10 → 22.6.0-beta.12
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/migrations.json +5 -0
- package/package.json +4 -4
- package/src/executors/test/lib/utils.d.ts +7 -0
- package/src/executors/test/lib/utils.d.ts.map +1 -1
- package/src/executors/test/lib/utils.js +16 -1
- package/src/migrations/update-22-6-0/prefix-reports-directory-with-project-root.d.ts +10 -0
- package/src/migrations/update-22-6-0/prefix-reports-directory-with-project-root.d.ts.map +1 -0
- package/src/migrations/update-22-6-0/prefix-reports-directory-with-project-root.js +105 -0
- package/src/utils/generator-utils.d.ts.map +1 -1
- package/src/utils/generator-utils.js +1 -1
package/migrations.json
CHANGED
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
},
|
|
18
18
|
"description": "Create AI Instructions to help migrate users workspaces past breaking changes for Vitest 4.",
|
|
19
19
|
"implementation": "./src/migrations/update-22-1-0/create-ai-instructions-for-vitest-4"
|
|
20
|
+
},
|
|
21
|
+
"update-22-6-0-prefix-reports-directory": {
|
|
22
|
+
"version": "22.6.0-beta.11",
|
|
23
|
+
"description": "Prefix reportsDirectory with {projectRoot} to maintain correct resolution after workspace-root-relative behavior change.",
|
|
24
|
+
"implementation": "./src/migrations/update-22-6-0/prefix-reports-directory-with-project-root"
|
|
20
25
|
}
|
|
21
26
|
},
|
|
22
27
|
"packageJsonUpdates": {
|
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": "22.6.0-beta.
|
|
4
|
+
"version": "22.6.0-beta.12",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"executors": "./executors.json",
|
|
53
53
|
"generators": "./generators.json",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@nx/devkit": "22.6.0-beta.
|
|
56
|
-
"@nx/js": "22.6.0-beta.
|
|
55
|
+
"@nx/devkit": "22.6.0-beta.12",
|
|
56
|
+
"@nx/js": "22.6.0-beta.12",
|
|
57
57
|
"tslib": "^2.3.0",
|
|
58
58
|
"semver": "^7.6.3",
|
|
59
59
|
"@phenomnomnominal/tsquery": "~6.1.4"
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"nx": "22.6.0-beta.
|
|
74
|
+
"nx": "22.6.0-beta.12"
|
|
75
75
|
},
|
|
76
76
|
"types": "./src/index.d.ts"
|
|
77
77
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { VitestExecutorOptions } from '../schema';
|
|
3
3
|
export declare function getOptions(options: VitestExecutorOptions, context: ExecutorContext, projectRoot: string): Promise<Record<string, any>>;
|
|
4
|
+
/**
|
|
5
|
+
* Nx's resolveNxTokensInOptions strips {workspaceRoot}/ from option values,
|
|
6
|
+
* leaving a workspace-root-relative path. However, vitest resolves
|
|
7
|
+
* reportsDirectory relative to the project root. This function converts
|
|
8
|
+
* the path to absolute so vitest resolves it correctly.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveReportsDirectory(reportsDirectory: string): string;
|
|
4
11
|
export declare function getOptionsAsArgv(obj: Record<string, any>): string[];
|
|
5
12
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../packages/vitest/src/executors/test/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../packages/vitest/src/executors/test/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAKhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAQlD,wBAAsB,UAAU,CAC9B,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAoG9B;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAKxE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,CAcnE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getOptions = getOptions;
|
|
4
|
+
exports.resolveReportsDirectory = resolveReportsDirectory;
|
|
4
5
|
exports.getOptionsAsArgv = getOptionsAsArgv;
|
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
|
6
7
|
const options_utils_1 = require("../../../utils/options-utils");
|
|
@@ -66,10 +67,24 @@ async function getOptions(options, context, projectRoot) {
|
|
|
66
67
|
resolved?.config?.['test']?.reporters,
|
|
67
68
|
coverage: {
|
|
68
69
|
...(coverage ?? {}),
|
|
69
|
-
...(reportsDirectory && {
|
|
70
|
+
...(reportsDirectory && {
|
|
71
|
+
reportsDirectory: resolveReportsDirectory(reportsDirectory),
|
|
72
|
+
}),
|
|
70
73
|
},
|
|
71
74
|
};
|
|
72
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Nx's resolveNxTokensInOptions strips {workspaceRoot}/ from option values,
|
|
78
|
+
* leaving a workspace-root-relative path. However, vitest resolves
|
|
79
|
+
* reportsDirectory relative to the project root. This function converts
|
|
80
|
+
* the path to absolute so vitest resolves it correctly.
|
|
81
|
+
*/
|
|
82
|
+
function resolveReportsDirectory(reportsDirectory) {
|
|
83
|
+
if ((0, path_1.isAbsolute)(reportsDirectory)) {
|
|
84
|
+
return reportsDirectory;
|
|
85
|
+
}
|
|
86
|
+
return (0, path_1.resolve)(devkit_1.workspaceRoot, reportsDirectory);
|
|
87
|
+
}
|
|
73
88
|
function getOptionsAsArgv(obj) {
|
|
74
89
|
const argv = [];
|
|
75
90
|
for (const [key, value] of Object.entries(obj)) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
/**
|
|
3
|
+
* Migrates reportsDirectory option for @nx/vitest:test and @nx/vite:test executors.
|
|
4
|
+
*
|
|
5
|
+
* Previously, reportsDirectory was resolved relative to the project root (cwd).
|
|
6
|
+
* Now it is resolved relative to the workspace root. This migration prepends
|
|
7
|
+
* {projectRoot}/ to existing naked paths so the resolved location stays the same.
|
|
8
|
+
*/
|
|
9
|
+
export default function prefixReportsDirectoryWithProjectRoot(tree: Tree): void;
|
|
10
|
+
//# sourceMappingURL=prefix-reports-directory-with-project-root.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefix-reports-directory-with-project-root.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/migrations/update-22-6-0/prefix-reports-directory-with-project-root.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,IAAI,EAIV,MAAM,YAAY,CAAC;AAQpB;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,qCAAqC,CAAC,IAAI,EAAE,IAAI,QAGvE"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = prefixReportsDirectoryWithProjectRoot;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
/**
|
|
8
|
+
* Migrates reportsDirectory option for @nx/vitest:test and @nx/vite:test executors.
|
|
9
|
+
*
|
|
10
|
+
* Previously, reportsDirectory was resolved relative to the project root (cwd).
|
|
11
|
+
* Now it is resolved relative to the workspace root. This migration prepends
|
|
12
|
+
* {projectRoot}/ to existing naked paths so the resolved location stays the same.
|
|
13
|
+
*/
|
|
14
|
+
function prefixReportsDirectoryWithProjectRoot(tree) {
|
|
15
|
+
migrateProjectConfigurations(tree);
|
|
16
|
+
migrateTargetDefaults(tree);
|
|
17
|
+
}
|
|
18
|
+
function migrateProjectConfigurations(tree) {
|
|
19
|
+
const projectsToUpdate = new Map();
|
|
20
|
+
for (const executorName of ['@nx/vitest:test', '@nx/vite:test']) {
|
|
21
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, executorName, (options, projectName, targetName, configuration) => {
|
|
22
|
+
if (needsMigration(options.reportsDirectory)) {
|
|
23
|
+
if (!projectsToUpdate.has(projectName)) {
|
|
24
|
+
projectsToUpdate.set(projectName, new Map());
|
|
25
|
+
}
|
|
26
|
+
const key = configuration
|
|
27
|
+
? `${targetName}::${configuration}`
|
|
28
|
+
: targetName;
|
|
29
|
+
projectsToUpdate
|
|
30
|
+
.get(projectName)
|
|
31
|
+
.set(key, { target: targetName, configuration });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
for (const [projectName] of projectsToUpdate) {
|
|
36
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
37
|
+
for (const [_targetName, target] of Object.entries(projectConfig.targets || {})) {
|
|
38
|
+
if (target.executor !== '@nx/vitest:test' &&
|
|
39
|
+
target.executor !== '@nx/vite:test') {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (needsMigration(target.options?.reportsDirectory)) {
|
|
43
|
+
target.options.reportsDirectory = prependProjectRoot(target.options.reportsDirectory);
|
|
44
|
+
}
|
|
45
|
+
if (target.configurations) {
|
|
46
|
+
for (const config of Object.values(target.configurations)) {
|
|
47
|
+
if (needsMigration(config?.reportsDirectory)) {
|
|
48
|
+
config.reportsDirectory = prependProjectRoot(config.reportsDirectory);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function migrateTargetDefaults(tree) {
|
|
57
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
58
|
+
if (!nxJson?.targetDefaults) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let hasChanges = false;
|
|
62
|
+
for (const [_key, targetConfig] of Object.entries(nxJson.targetDefaults)) {
|
|
63
|
+
if (targetConfig.executor !== '@nx/vitest:test' &&
|
|
64
|
+
targetConfig.executor !== '@nx/vite:test' &&
|
|
65
|
+
_key !== '@nx/vitest:test' &&
|
|
66
|
+
_key !== '@nx/vite:test') {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (needsMigration(targetConfig.options?.reportsDirectory)) {
|
|
70
|
+
targetConfig.options.reportsDirectory = prependProjectRoot(targetConfig.options.reportsDirectory);
|
|
71
|
+
hasChanges = true;
|
|
72
|
+
}
|
|
73
|
+
if (targetConfig.configurations) {
|
|
74
|
+
for (const config of Object.values(targetConfig.configurations)) {
|
|
75
|
+
if (needsMigration(config?.reportsDirectory)) {
|
|
76
|
+
config.reportsDirectory = prependProjectRoot(config.reportsDirectory);
|
|
77
|
+
hasChanges = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (hasChanges) {
|
|
83
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function needsMigration(reportsDirectory) {
|
|
87
|
+
if (!reportsDirectory) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if ((0, path_1.isAbsolute)(reportsDirectory)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
// Already starts with {projectRoot} — already project-root-relative
|
|
94
|
+
if (reportsDirectory.startsWith('{projectRoot}')) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
// Already starts with {workspaceRoot} — user intended workspace-root-relative
|
|
98
|
+
if (reportsDirectory.startsWith('{workspaceRoot}')) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
function prependProjectRoot(reportsDirectory) {
|
|
104
|
+
return `{projectRoot}/${reportsDirectory}`;
|
|
105
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/vitest/src/utils/generator-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,IAAI,EAGL,MAAM,YAAY,CAAC;AAMpB,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAC5D,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE3D,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;IACnD,gBAAgB,EAAE,IAAI,GAAG,UAAU,GAAG,QAAQ,CAAC;IAC/C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,WAAW,GAAG,cAAc,GAAG,MAAM,CAAC;IAC3E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,uBAAuB,CAAC,EAAE,MAAM,CAAC;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WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,WAAW,GAAG,cAAc,GAAG,MAAM,CAAC;IAC3E,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gBAAgB,CAAC,EAAE,IAAI,GAAG,UAAU,GAAG,QAAQ,CAAC;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,qBAAqB,EAC9B,UAAU,EAAE,OAAO,EACnB,YAAY,GAAE;IACZ,4BAA4B,CAAC,EAAE,WAAW,CAAC;IAC3C,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;CACrB,QA8MP"}
|
|
@@ -16,7 +16,7 @@ function addOrChangeTestTarget(tree, options, hasPlugin) {
|
|
|
16
16
|
}
|
|
17
17
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
18
18
|
const target = options.testTarget ?? 'test';
|
|
19
|
-
const reportsDirectory = (0, devkit_1.joinPathFragments)(
|
|
19
|
+
const reportsDirectory = (0, devkit_1.joinPathFragments)('coverage', project.root === '.' ? options.project : project.root);
|
|
20
20
|
const testOptions = {
|
|
21
21
|
reportsDirectory,
|
|
22
22
|
};
|