Skip to content

Commit 58b04e5

Browse files
committed
feat(cli): export vitest in /test sub path
1 parent 44a2989 commit 58b04e5

13 files changed

Lines changed: 98 additions & 92 deletions

File tree

packages/cli/build.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const { task } = await cli.build({
4040
const output = (await task).find((o) => o.kind === 'node');
4141

4242
await build({
43-
input: ['./src/bin.ts', './src/index.ts'],
44-
external: [/^node:/, 'rolldown-vite'],
43+
input: ['./src/bin.ts', './src/index.ts', './src/test.ts'],
44+
external: [/^node:/, 'rolldown-vite', 'vitest'],
4545
output: {
4646
format: 'esm',
4747
},
@@ -64,6 +64,7 @@ const program = createProgram({
6464
rootNames: [
6565
join(srcDir, 'index.ts'),
6666
join(srcDir, 'client.ts'),
67+
join(srcDir, 'test.ts'),
6768
],
6869
options: {
6970
...options,

packages/cli/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
},
1717
"./client": {
1818
"types": "./dist/client.d.ts"
19+
},
20+
"./test": {
21+
"import": "./dist/test.js",
22+
"types": "./dist/test.d.ts"
1923
}
2024
},
2125
"engines": {

packages/cli/src/bin.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
*/
1111

1212
import { run } from '../binding/index.js';
13-
import { doc } from './doc.js';
14-
import { fmt } from './fmt.js';
15-
import { lib } from './lib.js';
16-
import { lint } from './lint.js';
17-
import { test } from './test.js';
18-
import { vite } from './vite.js';
13+
import { doc } from './resolve-doc.js';
14+
import { fmt } from './resolve-fmt.js';
15+
import { lib } from './resolve-lib.js';
16+
import { lint } from './resolve-lint.js';
17+
import { test } from './resolve-test.js';
18+
import { vite } from './resolve-vite.js';
1919

2020
async function resolveUniversalViteConfig(err: null | Error, viteConfigCwd: string) {
2121
if (err) {

packages/cli/src/resolve-test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Vitest tool resolver for the vite-plus CLI.
3+
*
4+
* This module exports a function that resolves the Vitest binary path
5+
* using Node.js module resolution. The resolved path is passed back
6+
* to the Rust core, which then executes Vitest for running tests.
7+
*
8+
* Used for: `vite-plus test` command
9+
*/
10+
11+
import { DEFAULT_ENVS, resolve } from './utils.js';
12+
13+
/**
14+
* Resolves the Vitest binary path and environment variables.
15+
*
16+
* @returns Promise containing:
17+
* - binPath: Absolute path to the Vitest CLI entry point (vitest.mjs)
18+
* - envs: Environment variables to set when executing Vitest
19+
*
20+
* Vitest is Vite's testing framework that provides a Jest-compatible
21+
* testing experience with Vite's fast HMR and transformation pipeline.
22+
*/
23+
export async function test(): Promise<{
24+
binPath: string;
25+
envs: Record<string, string>;
26+
}> {
27+
// Resolve the Vitest CLI module directly
28+
const binPath = resolve('vitest/vitest.mjs');
29+
30+
return {
31+
binPath,
32+
// Pass through source map debugging environment variable if set
33+
envs: process.env.DEBUG_DISABLE_SOURCE_MAP
34+
? {
35+
...DEFAULT_ENVS,
36+
DEBUG_DISABLE_SOURCE_MAP: process.env.DEBUG_DISABLE_SOURCE_MAP,
37+
}
38+
: {
39+
...DEFAULT_ENVS,
40+
},
41+
};
42+
}

packages/cli/src/test.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1 @@
1-
/**
2-
* Vitest tool resolver for the vite-plus CLI.
3-
*
4-
* This module exports a function that resolves the Vitest binary path
5-
* using Node.js module resolution. The resolved path is passed back
6-
* to the Rust core, which then executes Vitest for running tests.
7-
*
8-
* Used for: `vite-plus test` command
9-
*/
10-
11-
import { DEFAULT_ENVS, resolve } from './utils.js';
12-
13-
/**
14-
* Resolves the Vitest binary path and environment variables.
15-
*
16-
* @returns Promise containing:
17-
* - binPath: Absolute path to the Vitest CLI entry point (vitest.mjs)
18-
* - envs: Environment variables to set when executing Vitest
19-
*
20-
* Vitest is Vite's testing framework that provides a Jest-compatible
21-
* testing experience with Vite's fast HMR and transformation pipeline.
22-
*/
23-
export async function test(): Promise<{
24-
binPath: string;
25-
envs: Record<string, string>;
26-
}> {
27-
// Resolve the Vitest CLI module directly
28-
const binPath = resolve('vitest/vitest.mjs');
29-
30-
return {
31-
binPath,
32-
// Pass through source map debugging environment variable if set
33-
envs: process.env.DEBUG_DISABLE_SOURCE_MAP
34-
? {
35-
...DEFAULT_ENVS,
36-
DEBUG_DISABLE_SOURCE_MAP: process.env.DEBUG_DISABLE_SOURCE_MAP,
37-
}
38-
: {
39-
...DEFAULT_ENVS,
40-
},
41-
};
42-
}
1+
export * from 'vitest';

0 commit comments

Comments
 (0)