Skip to content

Commit

Permalink
feat(cli): support passing --inspect and --inspect-brk
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 15, 2022
1 parent f34f2c1 commit ea80f2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/vitest/src/node/cli-wrapper.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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}`)

Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/node/cli.ts
Expand Up @@ -40,6 +40,8 @@ cli
.option('--sequence <options>', '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 <times>', '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
Expand Down

0 comments on commit ea80f2b

Please sign in to comment.