Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/guide/cli-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ Enables coverage collection. Can be overridden using the `--coverage` CLI option
- **CLI:** `--coverage.include <pattern>`
- **Config:** [coverage.include](/config/#coverage-include)

Files included in coverage as glob patterns. May be specified more than once when using multiple patterns (default: `**`)
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.

### coverage.exclude

- **CLI:** `--coverage.exclude <pattern>`
- **Config:** [coverage.exclude](/config/#coverage-exclude)

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))
Files to be excluded in coverage. May be specified more than once when using multiple extensions.

### coverage.clean

Expand Down Expand Up @@ -929,4 +929,4 @@ Use `bundle` to bundle the config with esbuild or `runner` (experimental) to pro

- **CLI:** `--standalone`

Start Vitest without running tests. File filters will be ignored, tests will be running only on change (default: `false`)
Start Vitest without running tests. Tests will be running only on change. This option is ignored when CLI file filters are passed. (default: `false`)
2 changes: 1 addition & 1 deletion packages/vitest/src/node/cli/cac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ async function collect(mode: VitestRunMode, cliFilters: string[], options: CliOp
...normalizeCliOptions(cliFilters, options),
watch: false,
run: true,
})
}, undefined, undefined, cliFilters)
if (!options.filesOnly) {
const { testModules: tests, unhandledErrors: errors } = await ctx.collect(cliFilters.map(normalize))

Expand Down
6 changes: 6 additions & 0 deletions packages/vitest/src/node/cli/cli-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export async function startVitest(
options,
viteOverrides,
vitestOptions,
cliFilters,
)

if (mode === 'test' && ctx.config.coverage.enabled) {
Expand Down Expand Up @@ -139,6 +140,7 @@ export async function prepareVitest(
options: CliOptions = {},
viteOverrides?: ViteUserConfig,
vitestOptions?: VitestOptions,
cliFilters?: string[],
): Promise<Vitest> {
process.env.TEST = 'true'
process.env.VITEST = 'true'
Expand All @@ -148,6 +150,10 @@ export async function prepareVitest(
options.watch = false
}

if (options.standalone && (cliFilters?.length || 0) > 0) {
options.standalone = false
}
Comment on lines +153 to +155
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed like the best place to do this. The resolveConfig doesn't have cliFilters in the scope.


// this shouldn't affect _application root_ that can be changed inside config
const root = resolve(options.root || process.cwd())

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
},
standalone: {
description:
'Start Vitest without running tests. File filters will be ignored, tests will be running only on change (default: `false`)',
'Start Vitest without running tests. Tests will be running only on change. This option is ignored when CLI file filters are passed. (default: `false`)',
},
mergeReports: {
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ export interface UserConfig extends InlineConfig {
*
* Vitest will only run tests if it's called programmatically or the test file changes.
*
* CLI file filters will be ignored.
* If CLI file filters are passed, standalone mode is ignored.
*/
standalone?: boolean

Expand Down
5 changes: 5 additions & 0 deletions test/cli/fixtures/standalone/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, test } from "vitest";

test("example", () => {
expect(1).toBe(1);
})
3 changes: 3 additions & 0 deletions test/cli/fixtures/standalone/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({})
29 changes: 29 additions & 0 deletions test/cli/test/standalone.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { test } from 'vitest'
import { runVitest } from '../../test-utils'

test('test run is not started when --standalone', async () => {
const { vitest } = await runVitest({
root: 'fixtures/standalone',
standalone: true,
watch: true,
})

await vitest.waitForStdout('Vitest is running in standalone mode. Edit a test file to rerun tests.')
await vitest.waitForStdout('PASS Waiting for file changes...')
await vitest.waitForStdout('press h to show help, press q to quit')
})

test('test run is started when --standalone and filename filter', async () => {
const { vitest } = await runVitest({
root: 'fixtures/standalone',
standalone: true,
watch: true,
}, ['basic.test.ts'])

await vitest.waitForStdout('✓ basic.test.ts > example')
await vitest.waitForStdout('Test Files 1 passed (1)')
await vitest.waitForStdout('Tests 1 passed (1)')

await vitest.waitForStdout('PASS Waiting for file changes...')
await vitest.waitForStdout('press h to show help, press q to quit')
})