@nx/vitest 22.4.0-canary.20260115-21d1555 → 22.4.0-canary.20260119-6bb82c0

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/PLUGIN.md ADDED
@@ -0,0 +1,41 @@
1
+ # Vitest
2
+
3
+ After making changes to a project, run the relevant test file to verify your changes work correctly.
4
+
5
+ ## Mode Detection
6
+
7
+ Check in order (first match wins):
8
+
9
+ | Mode | Detection |
10
+ | --------- | ------------------------------------------------------------------- |
11
+ | Atomized | `ciTargetName` in nx.json `@nx/vitest` or `@nx/vite` plugin options |
12
+ | Inference | `@nx/vitest` or `@nx/vite/plugin` in nx.json plugins array |
13
+ | Executor | `@nx/vitest:test` executor in project.json targets |
14
+
15
+ ## Run Specific Test File
16
+
17
+ ### Atomized
18
+
19
+ ```bash
20
+ nx run <project>:<ciTargetName>--<path/to/file.spec.ts>
21
+ # Example: nx run my-lib:test-ci--src/utils.spec.ts
22
+ ```
23
+
24
+ ### Inference
25
+
26
+ ```bash
27
+ nx test <project> -- <path/to/file.spec.ts>
28
+ ```
29
+
30
+ ### Executor
31
+
32
+ ```bash
33
+ nx run <project>:test --testFile=<path/to/file.spec.ts>
34
+ ```
35
+
36
+ ## Quick Reference
37
+
38
+ | Task | Atomized | Inference | Executor |
39
+ | ----------- | ---------------------------------------- | ----------------------------------- | ----------------------------------------------- |
40
+ | Run file | `nx run proj:test-ci--path/file.spec.ts` | `nx test proj -- path/file.spec.ts` | `nx run proj:test --testFile=path/file.spec.ts` |
41
+ | Run pattern | N/A | `nx test proj -- -t "pattern"` | `nx run proj:test --testNamePattern="pattern"` |
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.4.0-canary.20260115-21d1555",
4
+ "version": "22.4.0-canary.20260119-6bb82c0",
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.4.0-canary.20260115-21d1555",
56
- "@nx/js": "22.4.0-canary.20260115-21d1555",
55
+ "@nx/devkit": "22.4.0-canary.20260119-6bb82c0",
56
+ "@nx/js": "22.4.0-canary.20260119-6bb82c0",
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.4.0-canary.20260115-21d1555"
74
+ "nx": "22.4.0-canary.20260119-6bb82c0"
75
75
  },
76
76
  "types": "./src/index.d.ts"
77
77
  }
package/project.json CHANGED
@@ -40,6 +40,11 @@
40
40
  "glob": "**/*.d.ts",
41
41
  "output": "/"
42
42
  },
43
+ {
44
+ "input": "packages/vitest",
45
+ "glob": "PLUGIN.md",
46
+ "output": "/"
47
+ },
43
48
  {
44
49
  "input": "",
45
50
  "glob": "LICENSE",
@@ -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,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"}
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,GAClB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAuF9B;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,CAcnE"}
@@ -8,7 +8,7 @@ const path_1 = require("path");
8
8
  const executor_utils_1 = require("../../../utils/executor-utils");
9
9
  async function getOptions(options, context, projectRoot) {
10
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)();
11
+ const { loadConfigFromFile } = await (0, executor_utils_1.loadViteDynamicImport)();
12
12
  const viteConfigPath = (0, options_utils_1.normalizeViteConfigFilePath)(context.root, projectRoot, options.configFile);
13
13
  if (!viteConfigPath) {
14
14
  throw new Error((0, devkit_1.stripIndents) `
@@ -20,10 +20,10 @@ async function getOptions(options, context, projectRoot) {
20
20
  `);
21
21
  }
22
22
  const resolved = await loadConfigFromFile({
23
- mode: options?.mode ?? 'production',
23
+ mode: options?.mode ?? 'test',
24
24
  command: 'serve',
25
25
  }, viteConfigPath);
26
- if (!viteConfigPath || !resolved?.config?.['test']) {
26
+ if (!resolved?.config?.['test']) {
27
27
  devkit_1.logger.warn((0, devkit_1.stripIndents) `Unable to load test config from config file ${resolved?.path ?? viteConfigPath}
28
28
  Some settings may not be applied as expected.
29
29
  You can manually set the config in the project, ${context.projectName}, configuration.
@@ -33,23 +33,34 @@ async function getOptions(options, context, projectRoot) {
33
33
  ? process.cwd()
34
34
  : (0, path_1.relative)(context.cwd, (0, devkit_1.joinPathFragments)(context.root, projectRoot));
35
35
  const { parseCLI } = await (0, executor_utils_1.loadVitestDynamicImport)();
36
+ // Use parseCLI for Vitest-specific normalization/validation
36
37
  const { options: { watch, ...normalizedExtraArgs }, } = parseCLI(['vitest', ...getOptionsAsArgv(options)]);
37
- const { reportsDirectory, coverage, ...restNormalizedArgs } = normalizedExtraArgs;
38
- const settings = {
38
+ // Filter out options that are handled specially or are parseCLI artifacts
39
+ const {
40
+ // Handled specially by executor
41
+ testFiles: _testFiles, configFile: _configFile, mode: _mode, runMode: _runMode, reportsDirectory, coverage,
42
+ // parseCLI artifacts
43
+ '--': _dashdash, color: _color, w: _w,
44
+ // Pass through any additional Vitest options
45
+ ...passThroughOptions } = normalizedExtraArgs;
46
+ return {
39
47
  // Explicitly set watch mode to false if not provided otherwise vitest
40
48
  // will enable watch mode by default for non CI environments
41
49
  watch: watch ?? false,
42
- ...restNormalizedArgs,
50
+ // Pass through any additional Vitest options
51
+ ...passThroughOptions,
43
52
  // This should not be needed as it's going to be set in vite.config.ts
44
53
  // but leaving it here in case someone did not migrate correctly
45
- root: resolved.config.root ?? root,
54
+ root: resolved?.config?.root ?? root,
46
55
  config: viteConfigPath,
56
+ // Pass reporters from config so NxReporter can be merged without losing config reporters
57
+ // Safe: CLI options override (not merge with) config reporters, so no duplication
58
+ reporters: resolved?.config?.['test']?.reporters,
47
59
  coverage: {
48
60
  ...(coverage ?? {}),
49
61
  ...(reportsDirectory && { reportsDirectory }),
50
62
  },
51
63
  };
52
- return mergeConfig(resolved?.config?.['test'] ?? {}, settings);
53
64
  }
54
65
  function getOptionsAsArgv(obj) {
55
66
  const argv = [];
@@ -4,4 +4,5 @@ export interface VitestExecutorOptions {
4
4
  testFiles?: string[];
5
5
  watch?: boolean;
6
6
  mode?: string;
7
+ runMode?: 'test' | 'benchmark';
7
8
  }
@@ -19,7 +19,13 @@
19
19
  },
20
20
  "mode": {
21
21
  "type": "string",
22
- "description": "Mode for Vite."
22
+ "description": "Vite mode for loading configuration."
23
+ },
24
+ "runMode": {
25
+ "type": "string",
26
+ "description": "Vitest execution mode.",
27
+ "enum": ["test", "benchmark"],
28
+ "default": "test"
23
29
  },
24
30
  "testFiles": {
25
31
  "aliases": ["testFile"],
@@ -24,7 +24,7 @@ async function* vitestExecutor(options, context) {
24
24
  }
25
25
  resolvedOptions['reporters'].push(nxReporter);
26
26
  const cliFilters = options.testFiles ?? [];
27
- const ctx = await startVitest(resolvedOptions['mode'] ?? 'test', cliFilters, resolvedOptions);
27
+ const ctx = await startVitest(options.runMode ?? 'test', cliFilters, resolvedOptions);
28
28
  let hasErrors = false;
29
29
  const processExit = () => {
30
30
  ctx.exit();