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 .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export default ({ mode }: { mode: string }) => {
},
{
text: '跟踪查看器',
link: '/guide/browser/trace-viewer',
link: '/guide/browser/trace-view',
docFooterText: 'Trace Viewer | Browser Mode',
},
],
Expand Down
2 changes: 1 addition & 1 deletion advanced/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Advanced API
---

# 快速起步
# 快速起步 {#getting-started}

::: warning
本指南列出了通过 Node.js 脚本运行测试的高级 API。如果你只是想[运行测试](/guide/),你可能不需要这些内容。这些 API 主要用于库作者。
Expand Down
2 changes: 1 addition & 1 deletion advanced/api/reporters.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 报告器 「Reporters」
# 报告器 {#reporters}

::: warning
这是一个高级 API。如果我们只想配置内置的报告器,请阅读 ["Reporters"](/guide/reporters) 指南。
Expand Down
4 changes: 2 additions & 2 deletions advanced/api/vitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Vitest 4 新增了多个 API(它们都标记有 "4.0.0+" 徽章),并移除

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

### benchmark <Badge type="warning">实验性</Badge>
### benchmark <Badge type="warning">实验性</Badge> {#benchmark-experimental}

基准测试模式调用 `bench` 函数,并在遇到 `test` 或 `it` 时抛出错误。此模式使用配置中的 `benchmark.include` 和 `benchmark.exclude` 选项来查找基准测试文件。

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

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

## state <Badge type="warning">实验性</Badge>
## state <Badge type="warning">实验性</Badge> {#state-experimental}

::: warning
公共 `state` 是一个实验性 API(除了 `vitest.state.getReportedEntity`)。破坏性更改可能不遵循 SemVer,请在使用时固定 Vitest 的版本。
Expand Down
2 changes: 1 addition & 1 deletion advanced/metadata.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 任务元数据
# 任务元数据 {#task-metadata}

::: warning
Vitest 导出了实验性私有 API。重大更改可能不遵循 semver,使用时请固定 Vitest 的版本。
Expand Down
14 changes: 7 additions & 7 deletions advanced/reporters.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 扩展默认报告器 (Extending Reporters)
# 扩展默认报告器 {#extending-reporters}

::: warning
这是一个高级 API。如果我们只是想配置内置报告器,请阅读 [Reporters](/guide/reporters) 指南。
:::

我们可以从 `vitest/reporters` 导入报告器并扩展它们来创建自定义报告器。

## 扩展内置报告器 (Extending Built-in Reporters)
## 扩展内置报告器 {#extending-built-in-reporters}

一般来说,我们不需要从头开始创建报告器。`vitest` 附带了几个可以扩展的默认报告程序。

Expand Down Expand Up @@ -58,7 +58,7 @@ export default defineConfig({
})
```

## 报告的任务(Reported Tasks)
## 报告的任务 {#reported-tasks}

建议使用 Reported Tasks API,而不是使用报告器接收到的任务。

Expand All @@ -79,11 +79,11 @@ class MyReporter implements Reporter {
}
```

## 导出报告器 (Exported Reporters)
## 导出报告器 {#exported-reporters}

`vitest` 附带了一些[内置报告器](/guide/reporters),我们可以开箱即用。

### 内置报告器:
### 内置报告器: {#built-in-reporters}

1. `DefaultReporter`
2. `DotReporter`
Expand All @@ -95,10 +95,10 @@ class MyReporter implements Reporter {
8. `HangingProcessReporter`
9. `TreeReporter`

### 基础抽象报告器:
### 基础抽象报告器: {#base-abstract-reporters}

1. `BaseReporter`

### 接口报告器:
### 接口报告器: {#interface-reporters}

1. `Reporter`
6 changes: 3 additions & 3 deletions advanced/runner.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 运行器 API
# 运行器 API {#runner-api}

::: warning 注意
这是高级 API。如果你只需要[运行测试](/guide/),你可能不需要这个。它主要被库的作者使用。
Expand Down Expand Up @@ -150,7 +150,7 @@ export default class Runner {
快照支持和其他功能是依赖于测试运行器的。如果你想保留这些功能,可以从 `vitest/runners` 导入 `VitestTestRunner` 并将你的测试运行器继承该类。如果你想扩展基准测试功能,它还提供了 `NodeBenchmarkRunner`。
:::

## 你的任务函数
## Tasks {#tasks}

::: warning
“Runner Tasks API” 是实验性的,主要应在测试运行时使用。Vitest 还暴露了 [“Reported Tasks API”](/advanced/api/test-module),在主线程中工作时(例如在报告器内部)应优先使用。
Expand Down Expand Up @@ -275,7 +275,7 @@ export interface TaskResult {
}
```

## 你的任务函数
## 你的任务函数 {#your-task-function}

Vitest 提供了 `createTaskCollector` 工具来创建您自己的 `test` 方法。它的行为与测试相同,但在收集期间会调用自定义方法。

Expand Down
2 changes: 1 addition & 1 deletion api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
outline: deep
---

# Test API 索引
# Test API 索引 {#test-api-reference}

下面的类型签名中使用了以下类型:

Expand Down
2 changes: 1 addition & 1 deletion blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ outline: false
import BlogIndex from './.vitepress/components/BlogIndex.vue'
</script>

# Vitest 博客最新消息
# Vitest 博客最新消息 {#latest-from-the-vitest-blog}

<BlogIndex />
2 changes: 1 addition & 1 deletion config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
outline: deep
---

# 配置索引
# 配置索引 {#configuring-vitest}

如果我们正在使用 Vite 并且拥有一个 `vite.config` 文件,Vitest 会读取它来匹配我们的 Vite 应用的插件和设置。如果我们想要为测试配置不同的设置,或者我们的并不特别依赖于 Vite,我们我们可以选择:

Expand Down
2 changes: 1 addition & 1 deletion guide/browser/assertion-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ await expect.element(queryByTestId('prev')).not.toHaveSelection()
await expect.element(queryByTestId('next')).toHaveSelection('ne')
```

## toMatchScreenshot <Badge type="warning">实验性</Badge>
## toMatchScreenshot <Badge type="warning">实验性</Badge> {#tomatchscreenshot}

```ts
function toMatchScreenshot(
Expand Down
6 changes: 3 additions & 3 deletions guide/browser/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ outline: deep

命令是一个函数,它调用服务器上的另一个函数并将结果传递回浏览器。Vitest 公开了几个可以在浏览器测试中使用的内置命令。

## 内置命令
## 内置命令 {#built-in-commands}

### 文件处理
### 文件处理 {#files-handling}

在浏览器测试中,可借助 `readFile`、`writeFile` 与 `removeFile` 三个 API 完成文件操作。自 Vitest 3.2 起,所有路径均以 [project](/guide/projects) 根目录为基准解析(根目录默认为 `process.cwd()`,可手动重写);旧版本则以当前测试文件所在目录为基准。

Expand Down Expand Up @@ -122,7 +122,7 @@ declare module 'vitest/browser' {
如果自定义命令具有相同的名称,则它们将覆盖内置命令。
:::

### 自定义命令 `playwright`
### 自定义命令 `playwright` {#custom-playwright-commands}

Vitest 在命令上下文中公开了几个`playwright`特定属性。

Expand Down
Loading