@nx/vitest 0.0.1-alpha.0
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 +22 -0
- package/executors.json +10 -0
- package/generators.d.ts +4 -0
- package/generators.d.ts.map +1 -0
- package/generators.js +7 -0
- package/generators.json +18 -0
- package/index.d.ts +5 -0
- package/index.d.ts.map +1 -0
- package/index.js +9 -0
- package/migrations.json +9 -0
- package/package.json +69 -0
- package/project.json +52 -0
- package/src/executors/test/compat.d.ts +3 -0
- package/src/executors/test/compat.d.ts.map +1 -0
- package/src/executors/test/compat.js +5 -0
- package/src/executors/test/lib/nx-reporter.d.ts +19 -0
- package/src/executors/test/lib/nx-reporter.d.ts.map +1 -0
- package/src/executors/test/lib/nx-reporter.js +39 -0
- package/src/executors/test/lib/utils.d.ts +5 -0
- package/src/executors/test/lib/utils.d.ts.map +1 -0
- package/src/executors/test/lib/utils.js +68 -0
- package/src/executors/test/schema.d.ts +7 -0
- package/src/executors/test/schema.json +35 -0
- package/src/executors/test/vitest.impl.d.ts +7 -0
- package/src/executors/test/vitest.impl.d.ts.map +1 -0
- package/src/executors/test/vitest.impl.js +59 -0
- package/src/generators/configuration/configuration.d.ts +9 -0
- package/src/generators/configuration/configuration.d.ts.map +1 -0
- package/src/generators/configuration/configuration.js +284 -0
- package/src/generators/configuration/files/tsconfig.spec.json__tmpl__ +22 -0
- package/src/generators/configuration/schema.d.ts +16 -0
- package/src/generators/configuration/schema.json +65 -0
- package/src/generators/init/init.d.ts +8 -0
- package/src/generators/init/init.d.ts.map +1 -0
- package/src/generators/init/init.js +70 -0
- package/src/generators/init/schema.d.ts +11 -0
- package/src/generators/init/schema.json +41 -0
- package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.d.ts +3 -0
- package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.d.ts.map +1 -0
- package/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.js +17 -0
- package/src/plugins/plugin.d.ts +19 -0
- package/src/plugins/plugin.d.ts.map +1 -0
- package/src/plugins/plugin.js +277 -0
- package/src/utils/detect-ui-framework.d.ts +2 -0
- package/src/utils/detect-ui-framework.d.ts.map +1 -0
- package/src/utils/detect-ui-framework.js +24 -0
- package/src/utils/ensure-dependencies.d.ts +9 -0
- package/src/utils/ensure-dependencies.d.ts.map +1 -0
- package/src/utils/ensure-dependencies.js +47 -0
- package/src/utils/executor-utils.d.ts +3 -0
- package/src/utils/executor-utils.d.ts.map +1 -0
- package/src/utils/executor-utils.js +10 -0
- package/src/utils/generator-utils.d.ts +35 -0
- package/src/utils/generator-utils.d.ts.map +1 -0
- package/src/utils/generator-utils.js +223 -0
- package/src/utils/ignore-vitest-temp-files.d.ts +5 -0
- package/src/utils/ignore-vitest-temp-files.d.ts.map +1 -0
- package/src/utils/ignore-vitest-temp-files.js +54 -0
- package/src/utils/options-utils.d.ts +8 -0
- package/src/utils/options-utils.d.ts.map +1 -0
- package/src/utils/options-utils.js +41 -0
- package/src/utils/version-utils.d.ts +16 -0
- package/src/utils/version-utils.d.ts.map +1 -0
- package/src/utils/version-utils.js +90 -0
- package/src/utils/versions.d.ts +23 -0
- package/src/utils/versions.d.ts.map +1 -0
- package/src/utils/versions.js +26 -0
- package/src/utils/vite-config-edit-utils.d.ts +4 -0
- package/src/utils/vite-config-edit-utils.d.ts.map +1 -0
- package/src/utils/vite-config-edit-utils.js +359 -0
- package/tsconfig.json +28 -0
- package/tsconfig.lib.json +20 -0
- package/tsconfig.lib.tsbuildinfo +1 -0
- package/tsconfig.spec.json +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2025 Narwhal Technologies Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/executors.json
ADDED
package/generators.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../../../packages/vitest/generators.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AACtF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC"}
|
package/generators.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configurationGenerator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./src/generators/init/init"), exports);
|
|
6
|
+
var configuration_1 = require("./src/generators/configuration/configuration");
|
|
7
|
+
Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
|
package/generators.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Nx Vitest",
|
|
3
|
+
"version": "0.1",
|
|
4
|
+
"generators": {
|
|
5
|
+
"init": {
|
|
6
|
+
"factory": "./src/generators/init/init",
|
|
7
|
+
"schema": "./src/generators/init/schema.json",
|
|
8
|
+
"description": "Initialize the `@nx/vitest` plugin.",
|
|
9
|
+
"aliases": ["ng-add"],
|
|
10
|
+
"hidden": true
|
|
11
|
+
},
|
|
12
|
+
"configuration": {
|
|
13
|
+
"factory": "./src/generators/configuration/configuration",
|
|
14
|
+
"schema": "./src/generators/configuration/schema.json",
|
|
15
|
+
"description": "Add Vitest configuration to a project."
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createNodesV2, VitestPluginOptions } from './src/plugins/plugin';
|
|
2
|
+
export { VitestExecutorOptions } from './src/executors/test/schema';
|
|
3
|
+
export { vitestExecutor } from './src/executors/test/vitest.impl';
|
|
4
|
+
export { configurationGenerator } from './src/generators/configuration/configuration';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/vitest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configurationGenerator = exports.vitestExecutor = exports.createNodesV2 = void 0;
|
|
4
|
+
var plugin_1 = require("./src/plugins/plugin");
|
|
5
|
+
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
|
|
6
|
+
var vitest_impl_1 = require("./src/executors/test/vitest.impl");
|
|
7
|
+
Object.defineProperty(exports, "vitestExecutor", { enumerable: true, get: function () { return vitest_impl_1.vitestExecutor; } });
|
|
8
|
+
var configuration_1 = require("./src/generators/configuration/configuration");
|
|
9
|
+
Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
|
package/migrations.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nx/vitest",
|
|
3
|
+
"description": "The Nx Plugin for Vitest to enable fast unit testing with Vitest.",
|
|
4
|
+
"version": "0.0.1-alpha.0",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/nrwl/nx.git",
|
|
12
|
+
"directory": "packages/vitest"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/nrwl/nx/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"Monorepo",
|
|
19
|
+
"Vitest",
|
|
20
|
+
"Testing",
|
|
21
|
+
"Unit Testing"
|
|
22
|
+
],
|
|
23
|
+
"author": "Victor Savkin",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"homepage": "https://nx.dev",
|
|
26
|
+
"main": "index.js",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./index.d.ts",
|
|
30
|
+
"default": "./index.js"
|
|
31
|
+
},
|
|
32
|
+
"./generators": {
|
|
33
|
+
"types": "./generators.d.ts",
|
|
34
|
+
"default": "./generators.js"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json",
|
|
37
|
+
"./generators.json": "./generators.json",
|
|
38
|
+
"./executors.json": "./executors.json",
|
|
39
|
+
"./migrations.json": "./migrations.json"
|
|
40
|
+
},
|
|
41
|
+
"nx-migrations": {
|
|
42
|
+
"migrations": "./migrations.json"
|
|
43
|
+
},
|
|
44
|
+
"executors": "./executors.json",
|
|
45
|
+
"generators": "./generators.json",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@nx/devkit": "workspace:*",
|
|
48
|
+
"@nx/js": "workspace:*",
|
|
49
|
+
"tslib": "catalog:typescript",
|
|
50
|
+
"semver": "catalog:",
|
|
51
|
+
"@phenomnomnominal/tsquery": "catalog:typescript"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"vitest": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0",
|
|
55
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependenciesMeta": {
|
|
58
|
+
"vitest": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"vite": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"nx": "workspace:*"
|
|
67
|
+
},
|
|
68
|
+
"types": "./src/index.d.ts"
|
|
69
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vitest",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/vitest",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"targets": {
|
|
7
|
+
"build": {
|
|
8
|
+
"command": "node ./scripts/copy-readme.js vitest",
|
|
9
|
+
"outputs": ["{workspaceRoot}/build/packages/vitest/README.md"]
|
|
10
|
+
},
|
|
11
|
+
"legacy-post-build": {
|
|
12
|
+
"executor": "@nx/workspace-plugin:legacy-post-build",
|
|
13
|
+
"options": {
|
|
14
|
+
"tsConfig": "./tsconfig.lib.json",
|
|
15
|
+
"assets": [
|
|
16
|
+
{
|
|
17
|
+
"input": "packages/vitest",
|
|
18
|
+
"glob": "**/files/**",
|
|
19
|
+
"output": "/"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"input": "packages/vitest",
|
|
23
|
+
"glob": "**files/**/.gitkeep",
|
|
24
|
+
"output": "/"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"input": "packages/vitest",
|
|
28
|
+
"glob": "**/*.json",
|
|
29
|
+
"ignore": ["**/tsconfig*.json", "project.json", ".eslintrc.json"],
|
|
30
|
+
"output": "/"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"input": "packages/vitest",
|
|
34
|
+
"glob": "**/*.js",
|
|
35
|
+
"ignore": ["**/jest.config.js"],
|
|
36
|
+
"output": "/"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"input": "packages/vitest",
|
|
40
|
+
"glob": "**/*.d.ts",
|
|
41
|
+
"output": "/"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"input": "",
|
|
45
|
+
"glob": "LICENSE",
|
|
46
|
+
"output": "/"
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/executors/test/compat.ts"],"names":[],"mappings":";AAGA,wBAAiD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { File, Reporter } from 'vitest';
|
|
2
|
+
export declare class NxReporter implements Reporter {
|
|
3
|
+
private watch;
|
|
4
|
+
deferred: {
|
|
5
|
+
promise: Promise<boolean>;
|
|
6
|
+
resolve: (val: boolean) => void;
|
|
7
|
+
};
|
|
8
|
+
constructor(watch: boolean);
|
|
9
|
+
[Symbol.asyncIterator](): AsyncGenerator<{
|
|
10
|
+
hasErrors: boolean;
|
|
11
|
+
}, void, unknown>;
|
|
12
|
+
private setupDeferred;
|
|
13
|
+
/** Vitest ≥ 0.29 */
|
|
14
|
+
onTestRunEnd(files: any[], errors?: any): void;
|
|
15
|
+
/** Vitest ≤ 0.28 */
|
|
16
|
+
onFinished(files: File[], errors?: unknown[]): void;
|
|
17
|
+
private _handleFinished;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=nx-reporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nx-reporter.d.ts","sourceRoot":"","sources":["../../../../../../../packages/vitest/src/executors/test/lib/nx-reporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE7C,qBAAa,UAAW,YAAW,QAAQ;IAM7B,OAAO,CAAC,KAAK;IALzB,QAAQ,EAAE;QACR,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1B,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;KACjC,CAAC;gBAEkB,KAAK,EAAE,OAAO;IAI3B,CAAC,MAAM,CAAC,aAAa,CAAC;;;IAQ7B,OAAO,CAAC,aAAa;IAUrB,oBAAoB;IACpB,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,EAAE,GAAG;IAGvC,oBAAoB;IACpB,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE;IAK5C,OAAO,CAAC,eAAe;CAKxB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NxReporter = void 0;
|
|
4
|
+
class NxReporter {
|
|
5
|
+
constructor(watch) {
|
|
6
|
+
this.watch = watch;
|
|
7
|
+
this.setupDeferred();
|
|
8
|
+
}
|
|
9
|
+
async *[Symbol.asyncIterator]() {
|
|
10
|
+
do {
|
|
11
|
+
const hasErrors = await this.deferred.promise;
|
|
12
|
+
yield { hasErrors };
|
|
13
|
+
this.setupDeferred();
|
|
14
|
+
} while (this.watch);
|
|
15
|
+
}
|
|
16
|
+
setupDeferred() {
|
|
17
|
+
let resolve;
|
|
18
|
+
this.deferred = {
|
|
19
|
+
promise: new Promise((res) => {
|
|
20
|
+
resolve = res;
|
|
21
|
+
}),
|
|
22
|
+
resolve,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Vitest ≥ 0.29 */
|
|
26
|
+
onTestRunEnd(files, errors) {
|
|
27
|
+
this._handleFinished(files, errors);
|
|
28
|
+
}
|
|
29
|
+
/** Vitest ≤ 0.28 */
|
|
30
|
+
onFinished(files, errors) {
|
|
31
|
+
this._handleFinished(files, errors);
|
|
32
|
+
}
|
|
33
|
+
// --- private ----------------------------------------------------------
|
|
34
|
+
_handleFinished(files, errors) {
|
|
35
|
+
const hasErrors = files.some((f) => f.result?.state === 'fail') || errors?.length > 0;
|
|
36
|
+
this.deferred.resolve(hasErrors);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.NxReporter = NxReporter;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { VitestExecutorOptions } from '../schema';
|
|
3
|
+
export declare function getOptions(options: VitestExecutorOptions, context: ExecutorContext, projectRoot: string): Promise<Record<string, any>>;
|
|
4
|
+
export declare function getOptionsAsArgv(obj: Record<string, any>): string[];
|
|
5
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../packages/vitest/src/executors/test/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAIhB,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,gCAuEpB;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,CAcnE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOptions = getOptions;
|
|
4
|
+
exports.getOptionsAsArgv = getOptionsAsArgv;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const options_utils_1 = require("../../../utils/options-utils");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const executor_utils_1 = require("../../../utils/executor-utils");
|
|
9
|
+
async function getOptions(options, context, projectRoot) {
|
|
10
|
+
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
11
|
+
const { loadConfigFromFile, mergeConfig } = await (0, executor_utils_1.loadViteDynamicImport)();
|
|
12
|
+
const viteConfigPath = (0, options_utils_1.normalizeViteConfigFilePath)(context.root, projectRoot, options.configFile);
|
|
13
|
+
if (!viteConfigPath) {
|
|
14
|
+
throw new Error((0, devkit_1.stripIndents) `
|
|
15
|
+
Unable to load test config from config file ${viteConfigPath}.
|
|
16
|
+
|
|
17
|
+
Please make sure that vitest is configured correctly,
|
|
18
|
+
or use the @nx/vitest:configuration generator to configure it for you.
|
|
19
|
+
You can read more here: https://nx.dev/nx-api/vitest/generators/configuration
|
|
20
|
+
`);
|
|
21
|
+
}
|
|
22
|
+
const resolved = await loadConfigFromFile({
|
|
23
|
+
mode: options?.mode ?? 'production',
|
|
24
|
+
command: 'serve',
|
|
25
|
+
}, viteConfigPath);
|
|
26
|
+
if (!viteConfigPath || !resolved?.config?.['test']) {
|
|
27
|
+
devkit_1.logger.warn((0, devkit_1.stripIndents) `Unable to load test config from config file ${resolved?.path ?? viteConfigPath}
|
|
28
|
+
Some settings may not be applied as expected.
|
|
29
|
+
You can manually set the config in the project, ${context.projectName}, configuration.
|
|
30
|
+
`);
|
|
31
|
+
}
|
|
32
|
+
const root = projectRoot === '.'
|
|
33
|
+
? process.cwd()
|
|
34
|
+
: (0, path_1.relative)(context.cwd, (0, devkit_1.joinPathFragments)(context.root, projectRoot));
|
|
35
|
+
const { parseCLI } = await (0, executor_utils_1.loadVitestDynamicImport)();
|
|
36
|
+
const { options: { watch, ...normalizedExtraArgs }, } = parseCLI(['vitest', ...getOptionsAsArgv(options)]);
|
|
37
|
+
const { reportsDirectory, coverage, ...restNormalizedArgs } = normalizedExtraArgs;
|
|
38
|
+
const settings = {
|
|
39
|
+
// Explicitly set watch mode to false if not provided otherwise vitest
|
|
40
|
+
// will enable watch mode by default for non CI environments
|
|
41
|
+
watch: watch ?? false,
|
|
42
|
+
...restNormalizedArgs,
|
|
43
|
+
// This should not be needed as it's going to be set in vite.config.ts
|
|
44
|
+
// but leaving it here in case someone did not migrate correctly
|
|
45
|
+
root: resolved.config.root ?? root,
|
|
46
|
+
config: viteConfigPath,
|
|
47
|
+
coverage: {
|
|
48
|
+
...(coverage ?? {}),
|
|
49
|
+
...(reportsDirectory && { reportsDirectory }),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
return mergeConfig(resolved?.config?.['test'] ?? {}, settings);
|
|
53
|
+
}
|
|
54
|
+
function getOptionsAsArgv(obj) {
|
|
55
|
+
const argv = [];
|
|
56
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
value.forEach((item) => argv.push(`--${key}=${item}`));
|
|
59
|
+
}
|
|
60
|
+
else if (typeof value === 'object' && value !== null) {
|
|
61
|
+
argv.push(`--${key}='${JSON.stringify(value)}'`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
argv.push(`--${key}=${value}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return argv;
|
|
68
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Vitest executor",
|
|
6
|
+
"description": "Test using Vitest.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"configFile": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The path to the local vitest config, relative to the workspace root.",
|
|
12
|
+
"x-completion-type": "file",
|
|
13
|
+
"x-completion-glob": "@(vitest|vite).config@(.js|.ts)",
|
|
14
|
+
"aliases": ["config"]
|
|
15
|
+
},
|
|
16
|
+
"reportsDirectory": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Directory to write coverage report to."
|
|
19
|
+
},
|
|
20
|
+
"mode": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Mode for Vite."
|
|
23
|
+
},
|
|
24
|
+
"testFiles": {
|
|
25
|
+
"aliases": ["testFile"],
|
|
26
|
+
"type": "array",
|
|
27
|
+
"items": { "type": "string" }
|
|
28
|
+
},
|
|
29
|
+
"watch": {
|
|
30
|
+
"description": "Watch files for changes and rerun tests related to changed files.",
|
|
31
|
+
"type": "boolean"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"required": []
|
|
35
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { VitestExecutorOptions } from './schema';
|
|
3
|
+
export declare function vitestExecutor(options: VitestExecutorOptions, context: ExecutorContext): AsyncGenerator<never, {
|
|
4
|
+
success: boolean;
|
|
5
|
+
}, unknown>;
|
|
6
|
+
export default vitestExecutor;
|
|
7
|
+
//# sourceMappingURL=vitest.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/executors/test/vitest.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAiB,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAOjD,wBAAuB,cAAc,CACnC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,eAAe;;YAkEzB;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vitestExecutor = vitestExecutor;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const internal_1 = require("@nx/js/src/internal");
|
|
7
|
+
const nx_reporter_1 = require("./lib/nx-reporter");
|
|
8
|
+
const utils_1 = require("./lib/utils");
|
|
9
|
+
const executor_utils_1 = require("../../utils/executor-utils");
|
|
10
|
+
async function* vitestExecutor(options, context) {
|
|
11
|
+
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
12
|
+
(0, internal_1.registerTsConfigPaths)((0, path_1.resolve)(devkit_1.workspaceRoot, projectRoot, 'tsconfig.json'));
|
|
13
|
+
process.env.VITE_CJS_IGNORE_WARNING = 'true';
|
|
14
|
+
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
15
|
+
const { startVitest } = await (0, executor_utils_1.loadVitestDynamicImport)();
|
|
16
|
+
const resolvedOptions = (await (0, utils_1.getOptions)(options, context, projectRoot)) ?? {};
|
|
17
|
+
const watch = resolvedOptions['watch'] === true;
|
|
18
|
+
const nxReporter = new nx_reporter_1.NxReporter(watch);
|
|
19
|
+
if (resolvedOptions['reporters'] === undefined) {
|
|
20
|
+
resolvedOptions['reporters'] = [];
|
|
21
|
+
}
|
|
22
|
+
else if (typeof resolvedOptions['reporters'] === 'string') {
|
|
23
|
+
resolvedOptions['reporters'] = [resolvedOptions['reporters']];
|
|
24
|
+
}
|
|
25
|
+
resolvedOptions['reporters'].push(nxReporter);
|
|
26
|
+
const cliFilters = options.testFiles ?? [];
|
|
27
|
+
const ctx = await startVitest(resolvedOptions['mode'] ?? 'test', cliFilters, resolvedOptions);
|
|
28
|
+
let hasErrors = false;
|
|
29
|
+
const processExit = () => {
|
|
30
|
+
ctx.exit();
|
|
31
|
+
if (hasErrors) {
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
if (watch) {
|
|
39
|
+
process.on('SIGINT', processExit);
|
|
40
|
+
process.on('SIGTERM', processExit);
|
|
41
|
+
process.on('exit', processExit);
|
|
42
|
+
}
|
|
43
|
+
// vitest sets the exitCode in case of exception without notifying reporters
|
|
44
|
+
if (process.exitCode === undefined ||
|
|
45
|
+
(watch && ctx.state.getFiles().length > 0)) {
|
|
46
|
+
for await (const report of nxReporter) {
|
|
47
|
+
// vitest sets the exitCode = 1 when code coverage isn't met
|
|
48
|
+
hasErrors =
|
|
49
|
+
report.hasErrors || (process.exitCode && process.exitCode !== 0);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
hasErrors = process.exitCode !== 0;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
success: !hasErrors,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
exports.default = vitestExecutor;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { VitestGeneratorSchema } from './schema';
|
|
3
|
+
/**
|
|
4
|
+
* @param hasPlugin some frameworks (e.g. Nuxt) provide their own plugin. Their generators handle the plugin detection.
|
|
5
|
+
*/
|
|
6
|
+
export declare function configurationGenerator(tree: Tree, schema: VitestGeneratorSchema, hasPlugin?: boolean): Promise<GeneratorCallback>;
|
|
7
|
+
export declare function configurationGeneratorInternal(tree: Tree, schema: VitestGeneratorSchema, hasPlugin?: boolean): Promise<GeneratorCallback>;
|
|
8
|
+
export default configurationGenerator;
|
|
9
|
+
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/generators/configuration/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EASjB,IAAI,EAGL,MAAM,YAAY,CAAC;AAcpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAQjD;;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,8BAqLlB;AA2LD,eAAe,sBAAsB,CAAC"}
|