diff --git a/packages/vitest/src/node/cli-wrapper.ts b/packages/vitest/src/node/cli-wrapper.ts index 276c7b5a5557..63dc7f6da898 100644 --- a/packages/vitest/src/node/cli-wrapper.ts +++ b/packages/vitest/src/node/cli-wrapper.ts @@ -7,6 +7,7 @@ import c from 'picocolors' import { execa } from 'execa' const ENTRY = new URL('./cli.mjs', import.meta.url) +const NODE_ARGS = ['--inspect', '--inspect-brk'] interface ErrorDef { trigger: string @@ -69,18 +70,34 @@ have Vitest auto retries on flaky segfaults.\n`)) main() async function start(args: string[]) { - const child = execa('node', [fileURLToPath(ENTRY), ...args], { + const nodeArgs: string[] = [] + const vitestArgs: string[] = [] + + // move node args to the front + for (let i = 0; i < args.length; i++) { + let matched = false + for (const nodeArg of NODE_ARGS) { + if (args[i] === nodeArg || args[i].startsWith(`${nodeArg}=`)) { + matched = true + nodeArgs.push(args[i]) + break + } + } + if (!matched) + vitestArgs.push(args[i]) + } + + const child = execa('node', [...nodeArgs, fileURLToPath(ENTRY), ...vitestArgs], { reject: false, - all: true, stderr: 'pipe', stdout: 'inherit', stdin: 'inherit', }) child.stderr?.pipe(process.stderr) - const { all: output = '' } = await child + const { stdout } = await child for (const error of ERRORS) { - if (output.includes(error.trigger)) { + if (stdout.includes(error.trigger)) { if (process.env.GITHUB_ACTIONS) console.log(`::warning:: Segmentfault Error Detected: ${error.trigger}\nRefer to ${error.url}`) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index 988f900ca2ab..ba72347d602f 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -40,6 +40,8 @@ cli .option('--sequence ', 'Define in what order to run tests (use --sequence.shuffle to run tests in random order)') .option('--no-color', 'Removes colors from the console output') .option('--segfault-retry ', 'Return tests on segment fault (default: 0)', { default: 0 }) + .option('--inspect', 'Enable Node.js inspector') + .option('--inspect-brk', 'Enable Node.js inspector with break') .help() cli