Skip to content

Commit 0468f40

Browse files
committed
docs(en): merging all conflicts
2 parents da84e09 + 3a51312 commit 0468f40

26 files changed

Lines changed: 1251 additions & 6 deletions

.vitepress/config.ts

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,13 @@ export default ({ mode }: { mode: string }) => {
819819
},
820820
],
821821
},
822+
// Authoring — how to express a test in code: constructing it,
823+
// asserting, mocking dependencies, attaching metadata. The page is
824+
// about *test content*, not the runner. Discriminator: "How do I
825+
// write X in a test?" If yes, it belongs here. Mocking sub-pages
826+
// live nested because they're a multi-page subtopic.
822827
{
828+
<<<<<<< HEAD
823829
text: '指南',
824830
collapsed: false,
825831
items: [
@@ -845,6 +851,17 @@ export default ({ mode }: { mode: string }) => {
845851
},
846852
{
847853
text: '测试运行生命周期',
854+
=======
855+
text: 'Authoring',
856+
collapsed: false,
857+
items: [
858+
{
859+
text: 'Test Context',
860+
link: '/guide/test-context',
861+
},
862+
{
863+
text: 'Test Run Lifecycle',
864+
>>>>>>> 3a513123224c0041b8cda52ce1f47c912ce05789
848865
link: '/guide/lifecycle',
849866
},
850867
{
@@ -891,6 +908,7 @@ export default ({ mode }: { mode: string }) => {
891908
],
892909
},
893910
{
911+
<<<<<<< HEAD
894912
text: '并行测试',
895913
link: '/guide/parallelism',
896914
},
@@ -917,6 +935,10 @@ export default ({ mode }: { mode: string }) => {
917935
{
918936
text: '内联测试',
919937
link: '/guide/in-source',
938+
=======
939+
text: 'Test Tags',
940+
link: '/guide/test-tags',
941+
>>>>>>> 3a513123224c0041b8cda52ce1f47c912ce05789
920942
},
921943
{
922944
text: '测试注释',
@@ -927,9 +949,77 @@ export default ({ mode }: { mode: string }) => {
927949
link: '/guide/extending-matchers',
928950
},
929951
{
952+
<<<<<<< HEAD
930953
text: 'IDE 插件',
954+
=======
955+
text: 'Testing Types',
956+
link: '/guide/testing-types',
957+
},
958+
{
959+
text: 'In-Source Testing',
960+
link: '/guide/in-source',
961+
},
962+
],
963+
},
964+
// Workflow — how to invoke, select, and orchestrate test runs
965+
// across files/projects/processes. The page is about the *runner
966+
// and tooling around it*, not what's inside a test. Discriminator:
967+
// "How do I run / filter / parallelize / integrate Vitest?" If a
968+
// page is about the runtime environment of the tests themselves
969+
// (jsdom, node), it still belongs here — that's a workflow choice.
970+
{
971+
text: 'Workflow',
972+
collapsed: false,
973+
items: [
974+
{
975+
text: 'CLI',
976+
link: '/guide/cli',
977+
},
978+
{
979+
text: 'Test Filtering',
980+
link: '/guide/filtering',
981+
},
982+
{
983+
text: 'Test Projects',
984+
link: '/guide/projects',
985+
},
986+
{
987+
text: 'Test Environment',
988+
link: '/guide/environment',
989+
},
990+
{
991+
text: 'Parallelism',
992+
link: '/guide/parallelism',
993+
},
994+
{
995+
text: 'Reporters',
996+
link: '/guide/reporters',
997+
},
998+
{
999+
text: 'Vitest UI',
1000+
link: '/guide/ui',
1001+
},
1002+
{
1003+
text: 'IDE Integration',
1004+
>>>>>>> 3a513123224c0041b8cda52ce1f47c912ce05789
9311005
link: '/guide/ide',
9321006
},
1007+
],
1008+
},
1009+
// Quality & Debugging — how to verify the test run is healthy and
1010+
// diagnose it when it isn't. Coverage, perf, leak detection, error
1011+
// triage, observability. Discriminator: "Is my suite good?" or
1012+
// "Why did this fail / leak / slow down?" If a page primarily
1013+
// measures or fixes the suite (rather than authoring or running
1014+
// it), put it here.
1015+
{
1016+
text: 'Quality & Debugging',
1017+
collapsed: false,
1018+
items: [
1019+
{
1020+
text: 'Coverage',
1021+
link: '/guide/coverage',
1022+
},
9331023
{
9341024
text: '调试',
9351025
link: '/guide/debugging',
@@ -939,6 +1029,7 @@ export default ({ mode }: { mode: string }) => {
9391029
link: '/guide/common-errors',
9401030
},
9411031
{
1032+
<<<<<<< HEAD
9421033
text: '迁移指南',
9431034
link: '/guide/migration',
9441035
collapsed: false,
@@ -959,6 +1050,9 @@ export default ({ mode }: { mode: string }) => {
9591050
},
9601051
{
9611052
text: '性能',
1053+
=======
1054+
text: 'Performance',
1055+
>>>>>>> 3a513123224c0041b8cda52ce1f47c912ce05789
9621056
collapsed: false,
9631057
items: [
9641058
{
@@ -977,6 +1071,62 @@ export default ({ mode }: { mode: string }) => {
9771071
},
9781072
],
9791073
},
1074+
// Recipes — end-to-end patterns that solve a concrete problem by
1075+
// combining multiple features. Each entry is titled by the problem
1076+
// ("Database Transaction per Test"), not the feature. Add a recipe
1077+
// when a single feature page would over-explain, when the value
1078+
// comes from composition, or when users would search by intent
1079+
// rather than by API name.
1080+
{
1081+
text: 'Recipes',
1082+
collapsed: false,
1083+
items: [
1084+
{
1085+
text: 'Database Transaction per Test',
1086+
link: '/guide/recipes/db-transaction',
1087+
},
1088+
{
1089+
text: 'Cancelling Long-Running Operations Gracefully',
1090+
link: '/guide/recipes/cancellable',
1091+
},
1092+
{
1093+
text: 'Waiting for Async Conditions',
1094+
link: '/guide/recipes/wait-for',
1095+
},
1096+
{
1097+
text: 'Type Narrowing in Tests',
1098+
link: '/guide/recipes/type-narrowing',
1099+
},
1100+
{
1101+
text: 'Custom Assertion Helpers',
1102+
link: '/guide/recipes/custom-assertions',
1103+
},
1104+
{
1105+
text: 'Watching Non-Imported Files',
1106+
link: '/guide/recipes/watch-templates',
1107+
},
1108+
{
1109+
text: 'Extending Browser Locators',
1110+
link: '/guide/recipes/browser-locators',
1111+
},
1112+
{
1113+
text: 'Schema-Driven Assertions',
1114+
link: '/guide/recipes/schema-matching',
1115+
},
1116+
{
1117+
text: 'Auto-Cleanup with `using`',
1118+
link: '/guide/recipes/explicit-resources',
1119+
},
1120+
{
1121+
text: 'Per-File Isolation Settings',
1122+
link: '/guide/recipes/disable-isolation',
1123+
},
1124+
{
1125+
text: 'Parallel and Sequential Test Files',
1126+
link: '/guide/recipes/parallel-sequential',
1127+
},
1128+
],
1129+
},
9801130
{
9811131
text: '高级指南',
9821132
collapsed: true,
@@ -999,14 +1149,41 @@ export default ({ mode }: { mode: string }) => {
9991149
},
10001150
],
10011151
},
1152+
// Migration — one-time transitional content: cross-version
1153+
// upgrades and porting from other test runners (Jest, Mocha).
1154+
// Sits near the bottom because it's not daily-use and would push
1155+
// active-use guides further from the user's first scroll.
10021156
{
1157+
text: 'Migration',
1158+
link: '/guide/migration',
1159+
collapsed: false,
10031160
items: [
10041161
{
1162+
<<<<<<< HEAD
10051163
text: '测试技巧',
10061164
link: '/guide/recipes',
10071165
},
10081166
{
10091167
text: '测试框架比较',
1168+
=======
1169+
text: 'Migrating to Vitest 4.0',
1170+
link: '/guide/migration#vitest-4',
1171+
},
1172+
{
1173+
text: 'Migrating from Jest',
1174+
link: '/guide/migration#jest',
1175+
},
1176+
{
1177+
text: 'Migrating from Mocha + Chai + Sinon',
1178+
link: '/guide/migration#mocha-chai-sinon',
1179+
},
1180+
],
1181+
},
1182+
{
1183+
items: [
1184+
{
1185+
text: 'Comparisons',
1186+
>>>>>>> 3a513123224c0041b8cda52ce1f47c912ce05789
10101187
link: '/guide/comparisons',
10111188
},
10121189
],

api/advanced/vitest.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ title: Vitest API
77

88
Vitest 实例需要当前的测试模式。它可以是以下之一:
99

10+
<<<<<<< HEAD
1011
- `test`:运行运行时测试时
1112
- `benchmark`:运行基准测试时 <Badge type="warning">实验性</Badge>
13+
=======
14+
- `test` when running runtime tests
15+
- `benchmark` when running benchmarks <Experimental />
16+
>>>>>>> 3a513123224c0041b8cda52ce1f47c912ce05789
1217
1318
::: details New in Vitest 4
1419
Vitest 4 新增了多个 API(它们都标记有 "4.0.0+" 徽章),并移除了已弃用的 API:
@@ -31,7 +36,11 @@ Vitest 4 新增了多个 API(它们都标记有 "4.0.0+" 徽章),并移除
3136

3237
测试模式只会调用 `test``it` 中的函数,并在遇到 `bench` 时抛出错误。此模式使用配置中的 `include``exclude` 选项来查找测试文件。
3338

39+
<<<<<<< HEAD
3440
### benchmark <Badge type="warning">实验性</Badge> {#benchmark-experimental}
41+
=======
42+
### benchmark <Experimental /> {#benchmark}
43+
>>>>>>> 3a513123224c0041b8cda52ce1f47c912ce05789
3544
3645
基准测试模式调用 `bench` 函数,并在遇到 `test``it` 时抛出错误。此模式使用配置中的 `benchmark.include``benchmark.exclude` 选项来查找基准测试文件。
3746

@@ -47,7 +56,11 @@ Vitest 4 新增了多个 API(它们都标记有 "4.0.0+" 徽章),并移除
4756

4857
这是全局的 [`ViteDevServer`](https://vite.dev/guide/api-javascript#vitedevserver)
4958

59+
<<<<<<< HEAD
5060
## state <Badge type="warning">实验性</Badge> {#state-experimental}
61+
=======
62+
## state <Experimental /> {#state}
63+
>>>>>>> 3a513123224c0041b8cda52ce1f47c912ce05789
5164
5265
::: warning
5366
公共 `state` 是一个实验性 API(除了 `vitest.state.getReportedEntity`)。破坏性更改可能不遵循 SemVer,请在使用时固定 Vitest 的版本。

api/browser/assertions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,11 @@ await expect.element(queryByTestId('prev')).not.toHaveSelection()
10031003
await expect.element(queryByTestId('next')).toHaveSelection('ne')
10041004
```
10051005

1006+
<<<<<<< HEAD
10061007
## toMatchScreenshot <Badge type="warning">实验性</Badge> {#tomatchscreenshot}
1008+
=======
1009+
## toMatchScreenshot <Experimental /> {#tomatchscreenshot}
1010+
>>>>>>> 3a513123224c0041b8cda52ce1f47c912ce05789
10071011

10081012
```ts
10091013
function toMatchScreenshot(

api/vi.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ vi.useRealTimers()
10551055
### vi.useFakeTimers
10561056

10571057
```ts
1058-
function useFakeTimers(config?: FakeTimerInstallOpts): Vitest
1058+
function useFakeTimers(config?: FakeTimersConfig): Vitest
10591059
```
10601060

10611061
要启用模拟定时器,需要调用此方法。在调用 [`vi.useRealTimers()`](#vi-userealtimers) 之前,它将封装所有对定时器的进一步调用(如 `setTimeout``setInterval``clearTimeout``clearInterval``setImmediate``clearImmediate``Date`)。
@@ -1069,6 +1069,16 @@ function useFakeTimers(config?: FakeTimerInstallOpts): Vitest
10691069
仍然可以通过在 `toFake` 参数中指定选项来模拟: `vi.useFakeTimers({ toFake: ['nextTick', 'queueMicrotask'] })`
10701070
:::
10711071

1072+
You can use `toFake` to specify which timers to mock, or `toNotFake` to specify which timers to keep native. Note that `toFake` and `toNotFake` cannot be specified together.
1073+
1074+
```ts
1075+
// only mock setTimeout and clearTimeout
1076+
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
1077+
1078+
// mock all timers except setInterval
1079+
vi.useFakeTimers({ toNotFake: ['setInterval'] })
1080+
```
1081+
10721082
### vi.setTimerTickMode <Version>4.1.0</Version> {#vi-settimertickmode}
10731083

10741084
- **类型:**`(mode: 'manual' | 'nextTimerAsync') => Vitest | (mode: 'interval', interval?: number) => Vitest`
@@ -1342,7 +1352,7 @@ function resetConfig(): void
13421352

13431353
如果之前调用过 [`vi.setConfig`](#vi-setconfig) ,则会将配置重置为原始状态。
13441354

1345-
### vi.defineHelper <Version>4.1.0</Version> {#vi-defineHelper}
1355+
### vi.defineHelper <Version>4.1.0</Version> {#vi-definehelper}
13461356

13471357
```ts
13481358
function defineHelper<F extends (...args: any) => any>(fn: F): F

blog/vitest-3-2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export default defineConfig({
219219
test: {
220220
watchTriggerPatterns: [
221221
{
222-
pattern: /^src\/templates\/(.*)\.(ts|html|txt)$/,
222+
pattern: /src\/templates\/(.*)\.(ts|html|txt)$/,
223223
testsToRun: (file, match) => {
224224
return `api/tests/mailers/${match[2]}.test.ts`
225225
},

config/browser/webdriverio.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,27 @@ export default defineConfig({
6060
::: tip
6161
最有用的选项位于 `capabilities` 对象上。WebdriverIO 允许嵌套功能,但 Vitest 将忽略这些选项,因为我们依赖于不同的机制来生成多个浏览器。
6262

63+
<<<<<<< HEAD
6364
请注意,Vitest 将忽略 `capabilities.browserName` — 请改用 [`test.browser.instances.browser`](/config/browser/instances#browser)
65+
=======
66+
Note that Vitest will ignore `capabilities.browserName`; use [`test.browser.instances.browser`](/config/browser/instances#browser) instead.
67+
>>>>>>> 3a513123224c0041b8cda52ce1f47c912ce05789
6468
:::
69+
70+
## Headful Chrome in CI
71+
72+
Vitest enables [`browser.headless`](/config/browser/headless) automatically in CI.
73+
If you explicitly set `headless: false` for Chrome on a Linux CI runner, Chrome
74+
still needs a display server. Without one, WebDriverIO or ChromeDriver can fail
75+
with a misleading error such as `session not created: probably user data
76+
directory is already in use`.
77+
78+
Run the test command through `xvfb-run` when you need headful Chrome in GitHub
79+
Actions or another Linux CI environment:
80+
81+
```bash
82+
xvfb-run npm test
83+
```
84+
85+
Alternatively, keep `browser.headless` enabled in CI and use headful mode only
86+
for local debugging.

0 commit comments

Comments
 (0)