Skip to content

Commit f286921

Browse files
NoiseFansheremet-vahi-ogawacodexautofix-ci[bot]
authored
docs(en): merge docs-cn/sync-docs into docs-cn/dev @ a141f9d (#955)
* feat: add `experimental.preParse` flag (#10070) * feat(coverage): default to text reporter `skipFull` if agent detected (#10018) * docs: document browser mode auto cleanup behavior (#10045) Co-authored-by: Codex <noreply@openai.com> * feat(experimental): expose `assertion` as a public field (#10095) * docs: add "Learn" section (#10092) * docs(cn): dissolve the conflict * [autofix.ci] apply automated fixes --------- Co-authored-by: Vladimir <sleuths.slews0s@icloud.com> Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com> Co-authored-by: Codex <noreply@openai.com> Co-authored-by: noise <noisefan@163.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2 parents a060a86 + 97be22a commit f286921

28 files changed

Lines changed: 2220 additions & 191 deletions

.vitepress/config.ts

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,57 @@ export default ({ mode }: { mode: string }) => {
722722
},
723723
],
724724
},
725+
{
726+
text: 'Learn',
727+
collapsed: false,
728+
items: [
729+
{
730+
text: 'Writing Tests',
731+
link: '/guide/learn/writing-tests',
732+
docFooterText: 'Writing Tests | Learn',
733+
},
734+
{
735+
text: 'Using Matchers',
736+
link: '/guide/learn/matchers',
737+
docFooterText: 'Using Matchers | Learn',
738+
},
739+
{
740+
text: 'Testing Async Code',
741+
link: '/guide/learn/async',
742+
docFooterText: 'Testing Async Code | Learn',
743+
},
744+
{
745+
text: 'Setup and Teardown',
746+
link: '/guide/learn/setup-teardown',
747+
docFooterText: 'Setup and Teardown | Learn',
748+
},
749+
{
750+
text: 'Mock Functions',
751+
link: '/guide/learn/mock-functions',
752+
docFooterText: 'Mock Functions | Learn',
753+
},
754+
{
755+
text: 'Snapshot Testing',
756+
link: '/guide/learn/snapshots',
757+
docFooterText: 'Snapshot Testing | Learn',
758+
},
759+
{
760+
text: 'Testing in Practice',
761+
link: '/guide/learn/testing-in-practice',
762+
docFooterText: 'Testing in Practice | Learn',
763+
},
764+
{
765+
text: 'Debugging Tests',
766+
link: '/guide/learn/debugging-tests',
767+
docFooterText: 'Debugging Tests | Learn',
768+
},
769+
{
770+
text: 'Writing Tests with AI',
771+
link: '/guide/learn/writing-tests-with-ai',
772+
docFooterText: 'Writing Tests with AI | Learn',
773+
},
774+
],
775+
},
725776
{
726777
text: '浏览器模式',
727778
collapsed: false,
@@ -796,35 +847,35 @@ export default ({ mode }: { mode: string }) => {
796847
collapsed: true,
797848
items: [
798849
{
799-
text: '模拟日期',
850+
text: '日期',
800851
link: '/guide/mocking/dates',
801852
},
802853
{
803-
text: '模拟函数',
854+
text: '函数',
804855
link: '/guide/mocking/functions',
805856
},
806857
{
807-
text: '模拟全局对象',
858+
text: '全局对象',
808859
link: '/guide/mocking/globals',
809860
},
810861
{
811-
text: '模拟模块',
862+
text: '模块',
812863
link: '/guide/mocking/modules',
813864
},
814865
{
815-
text: '模拟文件系统',
866+
text: '文件系统',
816867
link: '/guide/mocking/file-system',
817868
},
818869
{
819-
text: '模拟请求',
870+
text: '请求',
820871
link: '/guide/mocking/requests',
821872
},
822873
{
823-
text: '模拟计时器',
874+
text: '计时器',
824875
link: '/guide/mocking/timers',
825876
},
826877
{
827-
text: '模拟类',
878+
text: '',
828879
link: '/guide/mocking/classes',
829880
},
830881
],

api/browser/interactivity.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ await originalUserEvent.keyboard('{/Shift}') // 没有放开 shift 键,因为
4040
这种行为更有用,因为我们并没有模拟键盘,而是实际按下了 Shift 键,所以保留原来的行为会在字段中键入时造成意想不到的问题。
4141
:::
4242

43+
::: warning
44+
With `playwright` and `webdriverio` providers, interactions are performed by the underlying browser driver. That means some interaction state, like pressed keys or pointer position and the resulting hover state, can persist between tests in the same file.
45+
46+
Vitest resets unreleased keyboard state automatically before starting each test case, but pointer position and the resulting hover state are not reset automatically since resetting pointer position can be expensive.
47+
48+
This applies both to `userEvent.*` calls and locator shortcuts like `locator.click()` or `locator.hover()`, because they use the same underlying interaction state.
49+
50+
If your tests depend on a neutral hover state, reset it explicitly, for example in `beforeEach`:
51+
52+
```ts
53+
import { beforeEach } from 'vitest'
54+
import { userEvent } from 'vitest/browser'
55+
56+
beforeEach(async () => {
57+
await userEvent.unhover(document.body)
58+
})
59+
```
60+
:::
61+
4362
## userEvent.click
4463

4564
```ts

config/coverage.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ npx vitest --coverage.enabled --coverage.provider=istanbul
132132
```
133133

134134
你可以在 Vitest UI 模式中查看代码覆盖率报告。更多详情请参阅 [Vitest UI Coverage](/guide/coverage#vitest-ui)
135+
<!-- TODO: translation -->
136+
::: tip AI coding agents
137+
When Vitest detects it is running inside an AI coding agent, it automatically adds the `text-summary` reporter and sets `skipFull: true` on the `text` reporter to reduce output and minimize token usage.
138+
:::
135139

136140
## coverage.reportOnFailure {#coverage-reportonfailure}
137141

config/experimental.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,36 @@ export default {
478478
如果禁用模块运行器,Vitest 会使用原生 [Node.js 模块加载器](https://nodejs.org/api/module.html#customization-hooks) 来转换文件,以支持 `import.meta.vitest``vi.mock``vi.hoisted` 功能。
479479

480480
如果你不使用这些特性,可禁用此功能以提升性能。
481+
<!-- TODO: translation -->
482+
## experimental.preParse <Version type="experimental">4.1.3</Version> {#experimental-preparse}
483+
484+
- **Type:** `boolean`
485+
- **Default:** `false`
486+
487+
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.
488+
489+
::: tip
490+
This option is recommended when using [`.only`](/api/test#test-only), the [`-t`](/config/testnamepattern) flag, or [`--tags-filter`](/guide/test-tags#syntax).
491+
492+
Enabling it unconditionally may slow down your test runs due to the additional parsing step.
493+
:::
494+
495+
::: warning
496+
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.
497+
498+
```ts
499+
// ✅ works — static string literal
500+
test('adds numbers', () => {})
501+
502+
// ✅ works — static tags
503+
test('my test', { tags: ['unit'] }, () => {})
504+
505+
// ❌ won't match correctly — dynamic name
506+
const name = getName()
507+
test(name, () => {})
508+
509+
// ❌ won't match correctly — dynamic tags
510+
const tags = getTags()
511+
test('my test', { tags }, () => {})
512+
```
513+
:::

config/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,11 @@ export default defineConfig(configEnv => mergeConfig(
7878
```
7979

8080
由于 Vitest 使用 Vite 的配置,我们也可以使用 [Vite](https://vitejs.dev/config/) 中的任何配置选项。例如,使用 `define` 来定义全局变量,或者使用 `resolve.alias` 来定义别名——这些选项应该在顶级定义,而不是在 `test` 属性内部。
81+
<!-- TODO: translation -->
82+
## Automatic Dependency Installation
83+
84+
Vitest will prompt you to install certain dependencies if they are not already installed. You can disable this behavior by setting the `VITEST_SKIP_INSTALL_CHECKS=1` environment variable.
85+
86+
## Config Options
8187

8288
[项目](/guide/projects) 配置中不支持的配置选项旁边会显示 <CRoot /> 图标。这意味着它们只能在 Vitest 根配置文件中进行设置。

guide/cli-generated.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,3 +963,10 @@ watch 模式下重新运行测试时清除终端屏幕(默认值:`true`)
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`)

guide/coverage.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,12 @@ export function ignored() { // [!code error]
510510

511511
<img alt="html coverage in Vitest UI" img-light src="/ui-coverage-1-light.png">
512512
<img alt="html coverage in Vitest UI" img-dark src="/ui-coverage-1-dark.png">
513+
<!-- TODO: translation -->
514+
## Coverage in Agent Environments
515+
516+
When Vitest detects it is running inside an AI coding agent, it automatically adjusts the default `text` reporter to reduce output and minimize token usage:
517+
518+
- `skipFull: true` is set on the `text` reporter, so files with 100% coverage are omitted from the terminal output.
519+
- The [`text-summary`](/config/coverage#coverage-reporter) reporter is added automatically, so the agent always sees a concise totals table even when `skipFull` hides all individual files.
520+
521+
These adjustments only apply when the `text` reporter is already part of the active reporter list (it is included in the default). Explicitly configured reporters are never removed.

guide/extending-matchers.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ When using the global `expect` with concurrent tests, `this.task` is `undefined`
156156

157157
断言是否以 [`soft`](/api/expect#soft) 方式调用。您无需手动处理该逻辑,Vitest 始终会捕获错误。
158158

159+
## `assertion` <Advanced /> <Version type="experimental">4.1.4</Version> {#assertion}
160+
161+
The underlying [Chai assertion](https://www.chaijs.com/guide/plugins/) object. This is the same instance that Chai plugins receive, giving you access to Chai's flag system and chainable methods. This can be useful for building custom matchers that need to interact with Chai's internals.
162+
159163
::: tip
160164
以上并非全部可用属性,仅列出最实用的部分。其他状态值由 Vitest 内部使用。
161165
:::

guide/features.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ import FeaturesList from '../.vitepress/components/FeaturesList.vue'
1616
## 一套配置可以运用在多种环境 {#shared-config-between-test-dev-and-build}
1717

1818
<div h-2 />
19+
<!-- TODO: translation -->
20+
::: tip
21+
This page is a high-level overview of Vitest's capabilities. If you're new to Vitest, we recommend reading the [Learn](/guide/learn/writing-tests) tutorial first for a hands-on introduction.
22+
:::
23+
24+
## Shared Config between Test, Dev and Build
1925

2026
与 Vite 的配置、转换器、解析器和插件通用,将会使用应用中的相同配置来运行测试。
2127

22-
了解更多信息 [配置 Vitest](/guide/#configuring-vitest)
28+
更多详情请参阅 [配置 Vitest](/config/)
2329

2430
## 监听模式(watch mode) {#watch-mode}
2531

0 commit comments

Comments
 (0)