Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion api/advanced/vitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function getRelevantTestSpecifications(
function mergeReports(directory?: string): Promise<TestRunResult>
```

合并指定目录中的多个运行的报告(如果未指定,则使用 `--merge-reports` 的值)。此值也可以在 `config.mergeReports` 上设置(默认情况下,它将读取 `.vitest-reports` 文件夹)。
合并指定目录中的多个运行的报告(如果未指定,则使用 `--merge-reports` 的值)。此值也可以在 `config.mergeReports` 上设置(默认情况下,它将读取 `.vitest/blob/` 文件夹)。

请注意,`directory` 将始终相对于工作目录解析。

Expand Down
8 changes: 4 additions & 4 deletions guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,16 @@ vitest run --shard=3/3
:::warning 警告
无法在启用 `--watch`(默认情况下在开发中启用)时使用此选项。
:::

<!-- TODO: translation reference history -->
::: tip
如果在没有输出文件的情况下使用 `--reporter=blob`,则默认路径将包括当前碎片配置,以避免与其他 Vitest 进程发生冲突。
If `--reporter=blob` is used without an output file, the default path will include the current shard config and blob label from `VITEST_BLOB_LABEL` or the blob reporter `label` option to avoid collisions with other Vitest processes.
:::

### merge-reports

- **类型:** `boolean | string`

合并位于指定文件夹中的每个 blob 报告(默认情况下为`.vitest-reports`)。你可以将任何报告程序与此命令一起使用([`blob`](/guide/reporters#blob-reporter) 除外):
<!-- TODO: translation reference history -->
Merges every blob report located in the specified folder (`.vitest/blob/` by default). You can use any reporters with this command (except [`blob`](/guide/reporters#blob-reporter)):

```sh
vitest --merge-reports --reporter=junit
Expand Down
42 changes: 17 additions & 25 deletions guide/improving-performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,20 @@ vitest run --reporter=blob --shard=3/3 # 3rd machine

> Vitest 对 _测试文件_(而非单个测试用例)进行分片。如果你有 1000 个测试文件,使用 `--shard=1/4` 时会运行其中的 250 个文件,而不会根据文件内的用例数量做进一步切分。

在各台机器上收集保存在 `.vitest-reports` 目录中的结果文件,然后通过 [`--merge-reports`](/guide/cli#merge-reports) 选项将这些结果合并:
在各台机器上收集保存在 `.vitest/blob/` 目录中的结果文件,然后通过 [`--merge-reports`](/guide/cli#merge-reports) 选项将这些结果合并:

```sh
vitest run --merge-reports
```
<!-- TODO: translation -->
When running the same shards across multiple environments, set the `VITEST_BLOB_LABEL` environment variable so merged reports can display them separately:

::: details GitHub Actions 示例
同样方案也应用于 https://github.com/vitest-tests/test-sharding 仓库。
```sh
VITEST_BLOB_LABEL=linux vitest run --reporter=blob --shard=1/3
```

::: details GitHub Actions example
This setup is also used at https://github.com/vitest-tests/test-sharding.

```yaml
# 灵感来至于 https://playwright.dev/docs/test-sharding
Expand All @@ -157,9 +163,10 @@ on:
- main
jobs:
tests:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
steps:
Expand All @@ -176,22 +183,15 @@ jobs:

- name: Run tests
run: pnpm run test --reporter=blob --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
env:
VITEST_BLOB_LABEL: ${{ matrix.os }}

- name: Upload blob report to GitHub Actions Artifacts
- name: Upload Vitest results GitHub Actions Artifacts
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: blob-report-${{ matrix.shardIndex }}
path: .vitest-reports/*
include-hidden-files: true
retention-days: 1

- name: Upload attachments to GitHub Actions Artifacts
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: blob-attachments-${{ matrix.shardIndex }}
path: .vitest/**
name: vitest-results-${{ matrix.os }}-${{ matrix.shardIndex }}
path: .vitest
include-hidden-files: true
retention-days: 1

Expand All @@ -212,18 +212,10 @@ jobs:
- name: Install dependencies
run: pnpm i

- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@v4
with:
path: .vitest-reports
pattern: blob-report-*
merge-multiple: true

- name: Download attachments from GitHub Actions Artifacts
- name: Download Vitest results from GitHub Actions Artifacts
uses: actions/download-artifact@v4
with:
path: .vitest
pattern: blob-attachments-*
merge-multiple: true

- name: Merge reports
Expand Down
27 changes: 23 additions & 4 deletions guide/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,19 +758,38 @@ export default defineConfig({
### Blob 报告器

将测试结果存储在计算机上,以便以后可以使用 [`--merge-reports`](/guide/cli#merge-reports) 命令进行合并。
默认情况下,将所有结果存储在 `.vitest-reports` 文件夹中,但可以用 `--outputFile` 或 `--outputFile.blob` 标志覆盖。
默认情况下,将所有结果存储在 `.vitest/blob/` 文件夹中,但可以用 `--outputFile` 或 `--outputFile.blob` 标志覆盖。

```bash
npx vitest --reporter=blob --outputFile=reports/blob-1.json
```

如果你在带有 [`--shard`](/guide/cli#shard) 标志的不同机器上运行 Vitest,我们建议你使用此报告程序。
使用 CI 管道末尾的 `--merge-reports` 命令,可以将所有 blob 报告合并到任何报告中:
<!-- TODO: translation -->
We recommend using this reporter if you are running Vitest on different machines with the [`--shard`](/guide/cli#shard) flag or across multiple environments (e.g., linux/macos/windows). All blob reports can be merged into any report by using `--merge-reports` command at the end of your CI pipeline:

```bash
npx vitest --merge-reports=reports --reporter=json --reporter=default
```

When running the same tests across multiple environments, use the `VITEST_BLOB_LABEL` environment variable to distinguish each environment's blob. Vitest reads labels at merge time and displays results separately:

```bash
VITEST_BLOB_LABEL=linux vitest run --reporter=blob
```

You can also provide the label via the blob reporter option. This has higher priority than `VITEST_BLOB_LABEL`.

```ts [vitest.config.ts]
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
reporters: [
['blob', { label: 'linux' }],
],
},
})
```

Blob reporter output doesn't include file-based [attachments](/api/advanced/artifacts.html#testattachment).
Make sure to merge [`attachmentsDir`](/config/attachmentsdir) separately alongside blob reports on CI when using this feature.

Expand Down
Loading