-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtest-watch.ts
More file actions
73 lines (57 loc) · 1.99 KB
/
Copy pathtest-watch.ts
File metadata and controls
73 lines (57 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as p from '@clack/prompts';
import { spawn } from 'node:child_process';
import { resolve } from 'node:path';
import { filterByScript, getWorkspacePackages } from './lib/workspace';
const ROOT = resolve(import.meta.dirname, '../..');
const main = async () => {
p.intro('Test Watch CLI');
const packages = getWorkspacePackages();
const testPackages = filterByScript(packages, 'test');
if (testPackages.length === 0) {
p.cancel('No packages with a `test` script found.');
process.exit(0);
}
// Single package: skip prompt and auto-select
const names: string[] =
testPackages.length === 1
? [testPackages[0].name]
: await (async () => {
const result = await p.multiselect({
message: 'Which packages to test in watch mode?',
options: testPackages.map(pkg => ({
value: pkg.name,
label: pkg.name,
hint: pkg.dir,
})),
required: true,
});
if (p.isCancel(result)) {
p.cancel('Cancelled.');
process.exit(0);
}
return result as string[];
})();
// Single package: spawn vitest directly for interactive stdin (keyboard shortcuts)
if (names.length === 1) {
const pkg = testPackages.find(tp => tp.name === names[0])!;
const pkgDir = resolve(ROOT, pkg.dir);
p.outro(`Running: vitest (interactive) in ${pkg.dir}`);
const child = spawn('npx', ['vitest'], {
cwd: pkgDir,
stdio: 'inherit',
shell: true,
});
child.on('exit', code => process.exit(code ?? 0));
return;
}
// Multiple packages: use turbo (no interactive stdin, but parallel output)
const filters = names.map(name => `--filter=${name}...`).join(' ');
p.outro(`Running: turbo test:watch ${filters}`);
const child = spawn('turbo', ['test:watch', ...filters.split(' ')], {
cwd: process.cwd(),
stdio: 'inherit',
shell: true,
});
child.on('exit', code => process.exit(code ?? 0));
};
main();