Skip to content

Commit f6897ad

Browse files
committed
fix(cli): vitest run --watch should be watch-mode
1 parent dfe81a6 commit f6897ad

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/vitest/src/node/cli/cac.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export function parseCLI(argv: string | string[], config: CliParseOptions = {}):
239239
if (arrayArgs[2] === 'watch' || arrayArgs[2] === 'dev') {
240240
options.watch = true
241241
}
242-
if (arrayArgs[2] === 'run') {
242+
if (arrayArgs[2] === 'run' && !options.watch) {
243243
options.run = true
244244
}
245245
if (arrayArgs[2] === 'related') {
@@ -265,7 +265,10 @@ async function watch(cliFilters: string[], options: CliOptions): Promise<void> {
265265
}
266266

267267
async function run(cliFilters: string[], options: CliOptions): Promise<void> {
268-
options.run = true
268+
// "vitest run --watch" should still be watch mode
269+
options.watch = options.watch === true
270+
options.run = !options.watch
271+
269272
await start('test', cliFilters, options)
270273
}
271274

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,15 @@ test('public parseCLI works correctly', () => {
381381
'color': true,
382382
},
383383
})
384+
expect(parseCLI('vitest run --watch')).toEqual({
385+
filter: [],
386+
options: {
387+
'watch': true,
388+
'w': true,
389+
'--': [],
390+
'color': true,
391+
},
392+
})
384393
expect(parseCLI('vitest related ./some-files.js')).toEqual({
385394
filter: [],
386395
options: {

0 commit comments

Comments
 (0)