Skip to content

Commit e2aa332

Browse files
committed
fix!: ignode --standalone when CLI filename filter is used
1 parent c1f78d2 commit e2aa332

File tree

8 files changed

+47
-4
lines changed

8 files changed

+47
-4
lines changed

docs/guide/cli-generated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,4 +929,4 @@ Use `bundle` to bundle the config with esbuild or `runner` (experimental) to pro
929929

930930
- **CLI:** `--standalone`
931931

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`)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ async function collect(mode: VitestRunMode, cliFilters: string[], options: CliOp
341341
...normalizeCliOptions(cliFilters, options),
342342
watch: false,
343343
run: true,
344-
})
344+
}, undefined, undefined, cliFilters)
345345
if (!options.filesOnly) {
346346
const { testModules: tests, unhandledErrors: errors } = await ctx.collect(cliFilters.map(normalize))
347347

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export async function startVitest(
5757
options,
5858
viteOverrides,
5959
vitestOptions,
60+
cliFilters,
6061
)
6162

6263
if (mode === 'test' && ctx.config.coverage.enabled) {
@@ -139,6 +140,7 @@ export async function prepareVitest(
139140
options: CliOptions = {},
140141
viteOverrides?: ViteUserConfig,
141142
vitestOptions?: VitestOptions,
143+
cliFilters?: string[],
142144
): Promise<Vitest> {
143145
process.env.TEST = 'true'
144146
process.env.VITEST = 'true'
@@ -148,6 +150,10 @@ export async function prepareVitest(
148150
options.watch = false
149151
}
150152

153+
if (options.standalone && (cliFilters?.length || 0) > 0) {
154+
options.standalone = false
155+
}
156+
151157
// this shouldn't affect _application root_ that can be changed inside config
152158
const root = resolve(options.root || process.cwd())
153159

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
820820
},
821821
standalone: {
822822
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`)',
824824
},
825825
mergeReports: {
826826
description:

packages/vitest/src/node/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ export interface UserConfig extends InlineConfig {
910910
*
911911
* Vitest will only run tests if it's called programmatically or the test file changes.
912912
*
913-
* CLI file filters will be ignored.
913+
* If CLI file filters are passed, standalone mode is ignored.
914914
*/
915915
standalone?: boolean
916916

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expect, test } from "vitest";
2+
3+
test("example", () => {
4+
expect(1).toBe(1);
5+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({})

test/cli/test/standalone.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
})

0 commit comments

Comments
 (0)