Skip to content

Commit 6ee832c

Browse files
authored
Merge pull request #984 from vitest-dev/sync-bac7cfdc-1
docs(en): merge docs-cn/sync-docs into docs-cn/dev @ bac7cfd
2 parents 8564192 + 74a1921 commit 6ee832c

4 files changed

Lines changed: 43 additions & 11 deletions

File tree

api/advanced/artifacts.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ If your custom artifact narrows the `attachments` type (e.g. to a tuple), includ
7878
export interface TestAttachment {
7979
/** MIME type of the attachment (e.g., 'image/png', 'text/plain') */
8080
contentType?: string
81-
/** File system path to the attachment */
81+
/** Local file path or external HTTP(S) URL to the attachment. Relative paths are resolved from the project root. */
8282
path?: string
8383
/** Inline attachment content as a string or raw binary data */
8484
body?: string | Uint8Array
@@ -94,7 +94,9 @@ export interface TestAttachment {
9494

9595
The `TestAttachment` interface represents a file or data attachment associated with a test artifact.
9696

97-
Attachments can be either file-based (via `path`) or inline content (via `body`). The `contentType` helps consumers understand how to interpret the attachment data.
97+
Attachments can be either path-based (via `path`) or inline content (via `body`). The `contentType` helps consumers understand how to interpret the attachment data.
98+
99+
Attachment `path` can point to a local file or an external `http`/`https` URL. Relative local paths are resolved from the project root. Local files are copied into Vitest's attachments directory before reporters receive them. External URLs are preserved as-is.
98100

99101
If you pass a string `body`, Vitest assumes it is already base64-encoded unless you set `bodyEncoding: 'utf-8'`. When you pass `body` as a `Uint8Array`, Vitest automatically encodes it as base64. The `bodyEncoding` option only applies to inline `body` attachments, not `path` attachments.
100102

config/disableconsoleintercept.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ outline: deep
88
- **类型:** `boolean`
99
- **命令行终端:** `--disableConsoleIntercept`
1010
- **默认值:** `false`
11+
<!-- TODO: translation -->
12+
By default, Vitest intercepts console output during tests to add context such as the test file and test title.
1113

12-
默认情况下,Vitest 会在测试期间自动拦截控制台日志,以便为测试文件、测试标题等添加额外格式。
14+
In [browser mode](/guide/browser/), this interception is required to forward logs from the browser DevTools to the terminal. It is also required for console log previews in the Vitest UI.
1315

14-
该功能也是 UI 模式控制台日志预览的必要条件。
15-
16-
不过,当你想要使用正常的同步终端控制台日志来调试代码时,禁用这种拦截可能会有帮助。
17-
18-
::: warning
19-
此选项对 [浏览器测试](/guide/browser/) 无效,因为 Vitest 会保留浏览器开发者工具中的原始日志记录。
20-
:::
16+
Disabling console interception can be useful when you want to debug code with normal synchronous terminal logging.

guide/reporters.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,29 @@ export default defineConfig({
535535
})
536536
```
537537

538+
:::
539+
<!-- TODO: translation -->
540+
Set `singleFile` to generate a self-contained HTML report:
541+
542+
```ts [vitest.config.ts]
543+
export default defineConfig({
544+
test: {
545+
reporters: [
546+
['html', { singleFile: true }],
547+
],
548+
},
549+
})
550+
```
551+
552+
When `singleFile` is enabled, Vitest inlines the UI assets, metadata, and test attachments into a single self-contained `index.html`. This makes the report easy to share, upload, or download as one artifact instead of preserving the whole `html` output directory.
553+
554+
::: warning
555+
`singleFile` has two caveats:
556+
557+
- The file can grow very large because everything is embedded inline — slow to open, memory-hungry, and possibly over the size limits of artifact viewers or static hosts.
558+
- Coverage HTML reports are not inlined yet and remain as separate files.
559+
560+
Prefer the default multi-file report when the suite has many or large attachments, or when you need coverage included in the bundle.
538561
:::
539562

540563
::: tip

guide/ui.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ npx vite preview --outDir ./html
5353
你可以使用 [`outputFile`](/config/outputfile) 配置选项配置输出。你需要在那里指定 `.html` 路径。例如,`./html/index.html` 是默认值。
5454
:::
5555

56+
If you need a portable report that can be opened or shared as one file, see [`singleFile`](/guide/reporters#html-reporter) in the HTML reporter documentation.
57+
5658
::: tip
5759
要在持续集成环境,例如 GitHub Actions 中查看 HTML 报告,请将输出目录作为产物上传:
5860

5961
```yaml
60-
- uses: actions/upload-artifact@v4
62+
- uses: actions/upload-artifact@v7
6163
id: upload-report
6264
with:
6365
name: vitest-report
@@ -68,6 +70,15 @@ npx vite preview --outDir ./html
6870
```
6971
7072
这会在任务摘要中添加一个链接。点击该链接即可在浏览器中直接通过 [Vitest Viewer](https://viewer.vitest.dev/) 查看报告。你也可以手动下载产物并解压,然后按照前文所述在本地运行 `vite preview` 命令。
73+
<!-- TODO: translation -->
74+
When you use `singleFile: true`, you can upload the report as a single file and it will become viewable directly GitHub artifacts with `archive: false` option:
75+
76+
```yaml
77+
- uses: actions/upload-artifact@v7
78+
with:
79+
path: html/index.html
80+
archive: false
81+
```
7182
:::
7283

7384
## 模块图 {#module-graph}

0 commit comments

Comments
 (0)