Skip to content

Commit 18fb4c5

Browse files
committed
docs(en): merging all conflicts
2 parents b008fda + 6d8f5db commit 18fb4c5

File tree

4 files changed

+135
-1
lines changed

4 files changed

+135
-1
lines changed

config/index.md

+8
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,14 @@ export default defineConfig({
17471747

17481748
在浏览器中运行时,默认情况下会启用此选项。如果你依赖于使用 `vi.spyOn` 监视 ES 模块,则可以启用此实验功能来监视模块导出。
17491749

1750+
#### browser.ui {#browser-ui}
1751+
1752+
- **Type:** `boolean`
1753+
- **Default:** `!isCI`
1754+
- **CLI:** `--browser.ui=false`
1755+
1756+
Should Vitest UI be injected into the page. By default, injects UI iframe during development.
1757+
17501758
#### browser.indexScripts {#browser-indexscripts}
17511759

17521760
- **类型:** `BrowserScript[]`

guide/features.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,17 @@ test('my types work properly', () => {
247247

248248
## 分片
249249

250+
<<<<<<< HEAD
250251
使用 [`--shard`](/guide/cli#shard)[`--reporter=blob`](/guide/reporters#blob-reporter)标志在不同的计算机上运行测试。可以使用 `--merge-reports` 命令在 CI 管道的末尾合并所有测试结果:
252+
=======
253+
Run tests on different machines using [`--shard`](/guide/cli#shard) and [`--reporter=blob`](/guide/reporters#blob-reporter) flags.
254+
All test and coverage results can be merged at the end of your CI pipeline using `--merge-reports` command:
255+
>>>>>>> 6d8f5db48f0b71948ed551f8b3001ef1fe5cae99
251256
252257
```bash
253258
vitest --shard=1/2 --reporter=blob
254259
vitest --shard=2/2 --reporter=blob
255-
vitest --merge-reports --reporter=junit
260+
vitest --merge-reports --reporter=junit --coverage.reporter=text
256261
```
262+
263+
See [`Improving Performance | Sharding`](/guide/improving-performance#sharding) for more information.

guide/improving-performance.md

+113
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,116 @@ export default defineConfig({
8585
```
8686

8787
:::
88+
89+
## Sharding
90+
91+
Test sharding means running a small subset of test cases at a time. It can be useful when you have multiple machines that could be used to run tests simultaneously.
92+
93+
To split Vitest tests on multiple different runs, use [`--shard`](/guide/cli#shard) option with [`--reporter=blob`](/guide/reporters#blob-reporter) option:
94+
95+
```sh
96+
vitest run --reporter=blob --shard=1/3 # 1st machine
97+
vitest run --reporter=blob --shard=2/3 # 2nd machine
98+
vitest run --reporter=blob --shard=3/3 # 3rd machine
99+
```
100+
101+
Collect the results stored in `.vitest-reports` directory from each machine and merge them with [`--merge-reports`](/guide/cli#merge-reports) option:
102+
103+
```sh
104+
vitest --merge-reports
105+
```
106+
107+
<details>
108+
<summary>Github action example</summary>
109+
110+
This setup is also used at https://github.com/vitest-tests/test-sharding.
111+
112+
```yaml
113+
# Inspired from https://playwright.dev/docs/test-sharding
114+
name: Tests
115+
on:
116+
push:
117+
branches:
118+
- main
119+
jobs:
120+
tests:
121+
runs-on: ubuntu-latest
122+
strategy:
123+
matrix:
124+
shardIndex: [1, 2, 3, 4]
125+
shardTotal: [4]
126+
steps:
127+
- uses: actions/checkout@v4
128+
- uses: actions/setup-node@v4
129+
with:
130+
node-version: 20
131+
132+
- name: Install pnpm
133+
uses: pnpm/action-setup@v4
134+
135+
- name: Install dependencies
136+
run: pnpm i
137+
138+
- name: Run tests
139+
run: pnpm run test --reporter=blob --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
140+
141+
- name: Upload blob report to GitHub Actions Artifacts
142+
if: ${{ !cancelled() }}
143+
uses: actions/upload-artifact@v4
144+
with:
145+
name: blob-report-${{ matrix.shardIndex }}
146+
path: .vitest-reports/*
147+
retention-days: 1
148+
149+
merge-reports:
150+
if: ${{ !cancelled() }}
151+
needs: [tests]
152+
153+
runs-on: ubuntu-latest
154+
steps:
155+
- uses: actions/checkout@v4
156+
- uses: actions/setup-node@v4
157+
with:
158+
node-version: 20
159+
160+
- name: Install pnpm
161+
uses: pnpm/action-setup@v4
162+
163+
- name: Install dependencies
164+
run: pnpm i
165+
166+
- name: Download blob reports from GitHub Actions Artifacts
167+
uses: actions/download-artifact@v4
168+
with:
169+
path: .vitest-reports
170+
pattern: blob-report-*
171+
merge-multiple: true
172+
173+
- name: Merge reports
174+
run: npx vitest --merge-reports
175+
```
176+
177+
</details>
178+
179+
:::tip
180+
Test sharding can also become useful on high CPU-count machines.
181+
182+
Vitest will run only a single Vite server in its main thread. Rest of the threads are used to run test files.
183+
In a high CPU-count machine the main thread can become a bottleneck as it cannot handle all the requests coming from the threads. For example in 32 CPU machine the main thread is responsible to handle load coming from 31 test threads.
184+
185+
To reduce the load from main thread's Vite server you can use test sharding. The load can be balanced on multiple Vite server.
186+
187+
```sh
188+
# Example for splitting tests on 32 CPU to 4 shards.
189+
# As each process needs 1 main thread, there's 7 threads for test runners (1+7)*4 = 32
190+
# Use VITEST_MAX_THREADS or VITEST_MAX_FORKS depending on the pool:
191+
VITEST_MAX_THREADS=7 vitest run --reporter=blob --shard=1/4 & \
192+
VITEST_MAX_THREADS=7 vitest run --reporter=blob --shard=2/4 & \
193+
VITEST_MAX_THREADS=7 vitest run --reporter=blob --shard=3/4 & \
194+
VITEST_MAX_THREADS=7 vitest run --reporter=blob --shard=4/4 & \
195+
wait # https://man7.org/linux/man-pages/man2/waitpid.2.html
196+
197+
vitest --merge-reports
198+
```
199+
200+
:::

guide/using-plugins.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ title: 使用插件 | 指南
44

55
# 使用插件
66

7+
<<<<<<< HEAD
78
Vitest 可以使用插件进行扩展...
9+
=======
10+
Vitest can be extended using plugins, similar to how Vite plugins work. This allows you to enhance and customize Vitest's functionality by using the same API and concepts of Vite plugins.
11+
12+
For detailed guidance on how to write plugins, you can refer to the [Vite plugin documentation](https://vitejs.dev/guide/api-plugin).
13+
>>>>>>> 6d8f5db48f0b71948ed551f8b3001ef1fe5cae99

0 commit comments

Comments
 (0)