[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!: ignore `--standalone` when CLI filename filter is used (#8262)

authored by

Ari Perkkiö and committed by
GitHub
(Jul 15, 2025, 4:26 PM +0200) 013bf2cb 88071a8f

+78 -6
+3 -3
docs/guide/cli-generated.md
··· 117 117 - **CLI:** `--coverage.include <pattern>` 118 118 - **Config:** [coverage.include](/config/#coverage-include) 119 119 120 - Files included in coverage as glob patterns. May be specified more than once when using multiple patterns (default: `**`) 120 + Files included in coverage as glob patterns. May be specified more than once when using multiple patterns. By default only files covered by tests are included. 121 121 122 122 ### coverage.exclude 123 123 124 124 - **CLI:** `--coverage.exclude <pattern>` 125 125 - **Config:** [coverage.exclude](/config/#coverage-exclude) 126 126 127 - Files to be excluded in coverage. May be specified more than once when using multiple extensions (default: Visit [`coverage.exclude`](https://vitest.dev/config/#coverage-exclude)) 127 + Files to be excluded in coverage. May be specified more than once when using multiple extensions. 128 128 129 129 ### coverage.clean 130 130 ··· 929 929 930 930 - **CLI:** `--standalone` 931 931 932 - Start Vitest without running tests. File filters will be ignored, tests will be running only on change (default: `false`) 932 + Start Vitest without running tests. Tests will be running only on change. This option is ignored when CLI file filters are passed. (default: `false`)
+29
docs/guide/migration.md
··· 116 116 117 117 Note that now if you provide an arrow function, you will get [`<anonymous> is not a constructor` error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_constructor) when the mock is called. 118 118 119 + ### Standalone mode with filename filter 120 + 121 + To improve user experience, Vitest will now start running the matched files when [`--standalone`](/guide/cli#standalone) is used with filename filter. 122 + 123 + ```sh 124 + # In Vitest v3 and below this command would ignore "math.test.ts" filename filter. 125 + # In Vitest v4 the math.test.ts will run automatically. 126 + $ vitest --standalone math.test.ts 127 + ``` 128 + 129 + This allows users to create re-usable `package.json` scripts for standalone mode. 130 + 131 + ::: code-group 132 + ```json [package.json] 133 + { 134 + "scripts": { 135 + "test:dev": "vitest --standalone" 136 + } 137 + } 138 + ``` 139 + ```bash [CLI] 140 + # Start Vitest in standalone mode, without running any files on start 141 + $ pnpm run test:dev 142 + 143 + # Run math.test.ts immediately 144 + $ pnpm run test:dev math.test.ts 145 + ``` 146 + ::: 147 + 119 148 ### Deprecated APIs are Removed 120 149 121 150 Vitest 4.0 removes some deprecated APIs, including:
+29
test/cli/test/standalone.test.ts
··· 1 + import { test } from 'vitest' 2 + import { runVitest } from '../../test-utils' 3 + 4 + test('test run is not started when --standalone', async () => { 5 + const { vitest } = await runVitest({ 6 + root: 'fixtures/standalone', 7 + standalone: true, 8 + watch: true, 9 + }) 10 + 11 + await vitest.waitForStdout('Vitest is running in standalone mode. Edit a test file to rerun tests.') 12 + await vitest.waitForStdout('PASS Waiting for file changes...') 13 + await vitest.waitForStdout('press h to show help, press q to quit') 14 + }) 15 + 16 + test('test run is started when --standalone and filename filter', async () => { 17 + const { vitest } = await runVitest({ 18 + root: 'fixtures/standalone', 19 + standalone: true, 20 + watch: true, 21 + }, ['basic.test.ts']) 22 + 23 + await vitest.waitForStdout('✓ basic.test.ts > example') 24 + await vitest.waitForStdout('Test Files 1 passed (1)') 25 + await vitest.waitForStdout('Tests 1 passed (1)') 26 + 27 + await vitest.waitForStdout('PASS Waiting for file changes...') 28 + await vitest.waitForStdout('press h to show help, press q to quit') 29 + })
+5
test/cli/fixtures/standalone/basic.test.ts
··· 1 + import { expect, test } from "vitest"; 2 + 3 + test("example", () => { 4 + expect(1).toBe(1); 5 + })
+3
test/cli/fixtures/standalone/vitest.config.ts
··· 1 + import { defineConfig } from 'vitest/config' 2 + 3 + export default defineConfig({})
+1 -1
packages/vitest/src/node/cli/cac.ts
··· 341 341 ...normalizeCliOptions(cliFilters, options), 342 342 watch: false, 343 343 run: true, 344 - }) 344 + }, undefined, undefined, cliFilters) 345 345 if (!options.filesOnly) { 346 346 const { testModules: tests, unhandledErrors: errors } = await ctx.collect(cliFilters.map(normalize)) 347 347
+6
packages/vitest/src/node/cli/cli-api.ts
··· 57 57 options, 58 58 viteOverrides, 59 59 vitestOptions, 60 + cliFilters, 60 61 ) 61 62 62 63 if (mode === 'test' && ctx.config.coverage.enabled) { ··· 139 140 options: CliOptions = {}, 140 141 viteOverrides?: ViteUserConfig, 141 142 vitestOptions?: VitestOptions, 143 + cliFilters?: string[], 142 144 ): Promise<Vitest> { 143 145 process.env.TEST = 'true' 144 146 process.env.VITEST = 'true' ··· 146 148 147 149 if (options.run) { 148 150 options.watch = false 151 + } 152 + 153 + if (options.standalone && (cliFilters?.length || 0) > 0) { 154 + options.standalone = false 149 155 } 150 156 151 157 // this shouldn't affect _application root_ that can be changed inside config
+1 -1
packages/vitest/src/node/cli/cli-config.ts
··· 820 820 }, 821 821 standalone: { 822 822 description: 823 - 'Start Vitest without running tests. File filters will be ignored, tests will be running only on change (default: `false`)', 823 + 'Start Vitest without running tests. Tests will be running only on change. This option is ignored when CLI file filters are passed. (default: `false`)', 824 824 }, 825 825 mergeReports: { 826 826 description:
+1 -1
packages/vitest/src/node/types/config.ts
··· 912 912 * 913 913 * Vitest will only run tests if it's called programmatically or the test file changes. 914 914 * 915 - * CLI file filters will be ignored. 915 + * If CLI file filters are passed, standalone mode is ignored. 916 916 */ 917 917 standalone?: boolean 918 918