Skip to content

Commit 3af71f2

Browse files
authored
feat: add experimental.preParse flag (#10070)
1 parent 82339b6 commit 3af71f2

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

config/experimental.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,36 @@ export default {
479479
If module runner is disabled, Vitest uses a native [Node.js module loader](https://nodejs.org/api/module.html#customization-hooks) to transform files to support `import.meta.vitest`, `vi.mock` and `vi.hoisted`.
480480

481481
If you don't use these features, you can disable this to improve performance.
482+
483+
## experimental.preParse <Version type="experimental">4.1.3</Version> {#experimental-preparse}
484+
485+
- **Type:** `boolean`
486+
- **Default:** `false`
487+
488+
Parses test specifications before running them. This applies the [`.only`](/api/test#test-only) modifier, the [`-t`](/config/testnamepattern) test name pattern, [`--tags-filter`](/guide/test-tags#syntax), [test lines](/api/advanced/test-specification#testlines), and [test IDs](/api/advanced/test-specification#testids) across all files without executing them. For example, if only a single test is marked with `.only`, Vitest will skip all other tests in all files.
489+
490+
::: tip
491+
This option is recommended when using [`.only`](/api/test#test-only), the [`-t`](/config/testnamepattern) flag, or [`--tags-filter`](/guide/test-tags#syntax).
492+
493+
Enabling it unconditionally may slow down your test runs due to the additional parsing step.
494+
:::
495+
496+
::: warning
497+
Pre-parsing uses static analysis (AST parsing) instead of executing your test files. This means that test names, tags, and modifiers (`.only`, `.skip`, `.todo`) must be statically analyzable. Dynamic test names (e.g., names stored in variables or returned from function calls) and non-literal tags will not be resolved correctly.
498+
499+
```ts
500+
// ✅ works — static string literal
501+
test('adds numbers', () => {})
502+
503+
// ✅ works — static tags
504+
test('my test', { tags: ['unit'] }, () => {})
505+
506+
// ❌ won't match correctly — dynamic name
507+
const name = getName()
508+
test(name, () => {})
509+
510+
// ❌ won't match correctly — dynamic tags
511+
const tags = getTags()
512+
test('my test', { tags }, () => {})
513+
```
514+
:::

guide/cli-generated.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,3 +963,10 @@ Controls whether Vitest will use Node.js Loader API to process in-source or mock
963963
- **Config:** [experimental.vcsProvider](/config/experimental#experimental-vcsprovider)
964964

965965
Custom provider for detecting changed files. (default: `git`)
966+
967+
### experimental.preParse
968+
969+
- **CLI:** `--experimental.preParse`
970+
- **Config:** [experimental.preParse](/config/experimental#experimental-preparse)
971+
972+
Parse test specifications before running them. This will apply `.only` flag and test name pattern across all files without running them. (default: `false`)

0 commit comments

Comments
 (0)