[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(cli): `vitest run --watch` should be watch-mode (#8128)

authored by

Ari Perkkiö and committed by
GitHub
(Jun 10, 2025, 5:33 PM +0200) 657e83f9 04f7a7f2

+41 -4
+2 -2
test/test-utils/index.ts
··· 190 190 } 191 191 192 192 // Manually stop the processes so that each test don't have to do this themselves 193 - afterEach(async () => { 193 + onTestFinished(async () => { 194 194 if (subprocess.exitCode === null) { 195 195 subprocess.kill() 196 196 } ··· 206 206 return output() 207 207 } 208 208 209 - if (args[0] !== 'list' && args.includes('--watch')) { 209 + if (args[0] !== 'list' && (args.includes('--watch') || args[0] === 'watch')) { 210 210 if (command === 'vitest') { 211 211 // Wait for initial test run to complete 212 212 await cli.waitForStdout('Waiting for file changes')
+22
test/config/test/mode.test.ts
··· 21 21 expect(stderr).toContain(`Error: env.mode should be equal to "${expectedMode}"`) 22 22 expect(stdout).toBe('') 23 23 }) 24 + 25 + test.each([ 26 + { options: ['run'], expected: 'run' }, 27 + { options: ['run', '--watch'], expected: 'watch' }, 28 + { options: ['watch'], expected: 'watch' }, 29 + ] as const)(`vitest $options.0 $options.1 resolves to $expected-mode`, async ({ options, expected }) => { 30 + const { vitest } = await testUtils.runVitestCli(...options, '--root', 'fixtures/run-mode') 31 + 32 + if (expected === 'watch') { 33 + await vitest.waitForStdout('Test Files 1 passed (1)') 34 + 35 + expect(vitest.stdout).not.toContain('RUN') 36 + expect(vitest.stdout).toContain('DEV') 37 + expect(vitest.stdout).toContain('Waiting for file changes') 38 + } 39 + 40 + if (expected === 'run') { 41 + expect(vitest.stdout).toContain('RUN') 42 + expect(vitest.stdout).not.toContain('DEV') 43 + expect(vitest.stdout).not.toContain('Waiting for file changes') 44 + } 45 + })
+9
test/core/test/cli-test.test.ts
··· 381 381 'color': true, 382 382 }, 383 383 }) 384 + expect(parseCLI('vitest run --watch')).toEqual({ 385 + filter: [], 386 + options: { 387 + 'watch': true, 388 + 'w': true, 389 + '--': [], 390 + 'color': true, 391 + }, 392 + }) 384 393 expect(parseCLI('vitest related ./some-files.js')).toEqual({ 385 394 filter: [], 386 395 options: {
+3
test/config/fixtures/run-mode/example.test.ts
··· 1 + import { test } from "vitest"; 2 + 3 + test("example", () => {})
+1
test/config/fixtures/run-mode/vitest.config.ts
··· 1 + export default {}
+4 -2
packages/vitest/src/node/cli/cac.ts
··· 239 239 if (arrayArgs[2] === 'watch' || arrayArgs[2] === 'dev') { 240 240 options.watch = true 241 241 } 242 - if (arrayArgs[2] === 'run') { 242 + if (arrayArgs[2] === 'run' && !options.watch) { 243 243 options.run = true 244 244 } 245 245 if (arrayArgs[2] === 'related') { ··· 265 265 } 266 266 267 267 async function run(cliFilters: string[], options: CliOptions): Promise<void> { 268 - options.run = true 268 + // "vitest run --watch" should still be watch mode 269 + options.run = !options.watch 270 + 269 271 await start('test', cliFilters, options) 270 272 } 271 273