Skip to content

Commit 751c392

Browse files
authored
fix(cli): parse --execArgv as array (#8924)
1 parent c9078a2 commit 751c392

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

docs/config/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,9 +724,14 @@ Similar as `vmThreads` pool but uses `child_process` instead of `worker_threads`
724724

725725
- **Type:** `string[]`
726726
- **Default:** `[]`
727+
- **CLI:** `--execArgv=<flag-1> --execArgv=<flag-2>`
727728

728729
Pass additional arguments to `node` in the runner worker. See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
729730

731+
```sh
732+
vitest --execArgv=--cpu-prof --execArgv=--cpu-prof-dir=./cpu-profile
733+
```
734+
730735
:::warning
731736
Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103.
732737
:::

packages/vitest/src/node/cli/cli-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
408408
execArgv: {
409409
description: 'Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.',
410410
argument: '<option>',
411+
array: true,
411412
},
412413
vmMemoryLimit: {
413414
description:

test/core/test/cli-test.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,13 @@ test('should include builtin reporters list', () => {
511511
const expected = Object.keys(ReportersMap)
512512
expect(new Set(listed)).toEqual(new Set(expected))
513513
})
514+
515+
test('execArgv can be passed', async () => {
516+
expect(getCLIOptions('--execArgv=--cpu-prof')).toEqual({
517+
execArgv: ['--cpu-prof'],
518+
})
519+
520+
expect(getCLIOptions('--execArgv=--cpu-prof --execArgv=--cpu-prof-dir=./cpu')).toEqual({
521+
execArgv: ['--cpu-prof', '--cpu-prof-dir=./cpu'],
522+
})
523+
})

0 commit comments

Comments
 (0)