From 03adc20c7ab24c769e0f950c6211026154d6f914 Mon Sep 17 00:00:00 2001 From: noise Date: Fri, 10 Apr 2026 00:50:37 +0800 Subject: [PATCH 1/6] docs(cn): complement the missing translation --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++-- api/advanced/plugin.md | 2 +- api/advanced/runner.md | 2 +- api/advanced/test-case.md | 4 ++-- api/advanced/test-specification.md | 4 +--- api/browser/commands.md | 2 +- api/browser/context.md | 4 ++-- api/browser/interactivity.md | 2 +- api/browser/locators.md | 12 ++++------ api/browser/svelte.md | 2 +- api/browser/vue.md | 6 ++--- api/expect.md | 4 ++-- config/bail.md | 2 +- config/browser/preview.md | 2 +- config/coverage.md | 6 ++--- config/css.md | 4 ++-- config/experimental.md | 6 ++--- config/file.md | 2 +- config/index.md | 8 +++---- config/snapshotformat.md | 2 +- config/ui.md | 2 +- guide/advanced/tests.md | 2 +- guide/browser/trace-view.md | 26 ++++++++++----------- guide/cli-generated.md | 36 ++++++++++++++--------------- guide/coverage.md | 12 +++++----- guide/debugging.md | 2 +- guide/extending-matchers.md | 2 +- guide/features.md | 8 +++---- guide/improving-performance.md | 12 +++++----- guide/lifecycle.md | 4 ++-- guide/migration.md | 2 +- guide/mocking.md | 6 ++--- guide/profiling-test-performance.md | 2 +- guide/reporters.md | 4 ++-- guide/snapshot.md | 12 +++++----- guide/test-tags.md | 10 ++++---- guide/testing-types.md | 6 ++--- guide/ui.md | 6 ++--- guide/why.md | 6 ++--- 39 files changed, 118 insertions(+), 122 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 0c4a7daf3..12cd4a416 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,6 +1,6 @@ -### 在提交PR之前,请确保您执行以下操作: +### 在提交PR之前,请确保你执行以下操作: - [ ] 曾阅读过[翻译须知](https://github.com/vitest-dev/docs-cn/issues/391)。 - [ ] 检查是否已经有PR以同样的方式解决问题,以避免创建重复。 - [ ] 在此PR中描述正在解决的问题,或引用它解决的问题(例如:`fixes #123`)。 @@ -8,7 +8,7 @@ --- ### 描述 - + ### 附加上下文 diff --git a/api/advanced/plugin.md b/api/advanced/plugin.md index 1b447e17e..de755dcf6 100644 --- a/api/advanced/plugin.md +++ b/api/advanced/plugin.md @@ -93,7 +93,7 @@ function injectTestProjects( ```ts // 为单个项目注入自定义别名 const newProjects = await injectTestProjects({ - // 您可以通过引用 `extends` 来继承当前项目配置 + // 你可以通过引用 `extends` 来继承当前项目配置 // 注意,不能使用已经存在的项目名称, // 所以定义自定义名称是一个好实践。 extends: project.vite.config.configFile, diff --git a/api/advanced/runner.md b/api/advanced/runner.md index 157e935eb..b7279c69a 100644 --- a/api/advanced/runner.md +++ b/api/advanced/runner.md @@ -275,7 +275,7 @@ export interface TaskResult { ## 你的任务函数 {#your-task-function} -Vitest 提供了 `createTaskCollector` 工具来创建您自己的 `test` 方法。它的行为与测试相同,但在收集期间会调用自定义方法。 +Vitest 提供了 `createTaskCollector` 工具来创建你自己的 `test` 方法。它的行为与测试相同,但在收集期间会调用自定义方法。 任务是套件的一部分对象。它会通过 `suite.task` 方法自动添加到当前套件中: diff --git a/api/advanced/test-case.md b/api/advanced/test-case.md index 356e1aab0..8fbccd5a7 100644 --- a/api/advanced/test-case.md +++ b/api/advanced/test-case.md @@ -1,8 +1,8 @@ # TestCase -`TestCase` 类表示单个测试。此类仅在主线程中可用。如果您正在处理运行时任务,请参阅 [“运行器 API”](/api/advanced/runner#tasks)。 +`TestCase` 类表示单个测试。此类仅在主线程中可用。如果你正在处理运行时任务,请参阅 [“运行器 API”](/api/advanced/runner#tasks)。 -`TestCase` 实例始终有一个值为 `test` 的 `type` 属性。您可以使用它来区分不同的任务类型: +`TestCase` 实例始终有一个值为 `test` 的 `type` 属性。你可以使用它来区分不同的任务类型: ```ts if (task.type === 'test') { diff --git a/api/advanced/test-specification.md b/api/advanced/test-specification.md index 6ae9a1670..1bb3b3c0d 100644 --- a/api/advanced/test-specification.md +++ b/api/advanced/test-specification.md @@ -44,10 +44,8 @@ Vite 模块图中的模块 ID。通常,它是一个使用 POSIX 分隔符的 测试模块将运行的 [`pool`](/config/pool)。 - - ::: danger -It's possible to have multiple pools in a single test project with [`typecheck.enabled`](/config/typecheck#typecheck-enabled). This means it's possible to have several specifications with the same `moduleId` but different `pool`. In later versions, the project will only support a single pool. +在启用 [`typecheck.enabled`](/config/typecheck#typecheck-enabled) 配置的情况下,单个测试项目中可能存在多个运行池。这意味着可能出现多个测试规范共享相同 `moduleId` 但使用不同 `pool` 的情况。请注意,后续版本将仅支持单一运行池模式。 ::: ## testLines diff --git a/api/browser/commands.md b/api/browser/commands.md index 3f43b0794..0293fe511 100644 --- a/api/browser/commands.md +++ b/api/browser/commands.md @@ -131,7 +131,7 @@ declare module 'vitest/browser' { Vitest 在命令上下文中公开了几个`playwright`特定属性。 - `page`引用包含测试 iframe 的完整页面。这是协调器 HTML,为避免出现问题,最好不要碰它。 -- `frame` 是一个异步方法,用于解析测试器 [`Frame`](https://playwright.dev/docs/api/class-frame)。它的 API 与 `page` 类似,但不支持某些方法。如果您需要查询元素,应优先使用 `context.iframe` 代替,因为它更稳定、更快速。 +- `frame` 是一个异步方法,用于解析测试器 [`Frame`](https://playwright.dev/docs/api/class-frame)。它的 API 与 `page` 类似,但不支持某些方法。如果你需要查询元素,应优先使用 `context.iframe` 代替,因为它更稳定、更快速。 - `iframe` 是一个 [`FrameLocator`](https://playwright.dev/docs/api/class-framelocator),用于查询页面上的其他元素。 - `context` 是指唯一的[BrowserContext](https://playwright.dev/docs/api/class-browsercontext)。 diff --git a/api/browser/context.md b/api/browser/context.md index 7d6ecdd0b..ddbdbce36 100644 --- a/api/browser/context.md +++ b/api/browser/context.md @@ -59,10 +59,10 @@ export const commands: BrowserCommands 页面导出提供了与当前页面交互的实用程序。 ::: warning -虽然它从 Playwright 的 `page` 中获取了一些实用程序,但它与 Playwright 的 `page` 并不是同一个对象。由于浏览器上下文是在浏览器中评估的,您的测试无法访问 Playwright 的 `page`,因为它是在服务器上运行的。 +虽然它从 Playwright 的 `page` 中获取了一些实用程序,但它与 Playwright 的 `page` 并不是同一个对象。由于浏览器上下文是在浏览器中评估的,你的测试无法访问 Playwright 的 `page`,因为它是在服务器上运行的。 ::: -使用 [Commands API](/api/browser/commands) 如果您需要访问 Playwright 的 `page` 对象。 +使用 [Commands API](/api/browser/commands) 如果你需要访问 Playwright 的 `page` 对象。 ```ts export const page: { diff --git a/api/browser/interactivity.md b/api/browser/interactivity.md index cdf212112..b154bb300 100644 --- a/api/browser/interactivity.md +++ b/api/browser/interactivity.md @@ -259,7 +259,7 @@ test('update input', async () => { }) ``` -该方法聚焦元素、填充元素并在填充后触发一个 `input` 事件。您可以使用空字符串来清除字段。 +该方法聚焦元素、填充元素并在填充后触发一个 `input` 事件。你可以使用空字符串来清除字段。 ::: tip 该 API 比使用 [`userEvent.type`](#userevent-type) 或 [`userEvent.keyboard`](#userevent-keyboard) 更快,但**不支持** [user-event `keyboard` syntax](https://testing-library.com/docs/user-event/keyboard) (例如,`{Shift}{selectall}`)。 diff --git a/api/browser/locators.md b/api/browser/locators.md index 023a8bc1c..ae420fabf 100644 --- a/api/browser/locators.md +++ b/api/browser/locators.md @@ -850,9 +850,9 @@ const { path, base64 } = await button.screenshot({ function mark(name: string, options?: { stack?: string }): Promise ``` -Adds a named marker to the trace timeline and uses the current locator as marker context. +在追踪时间线上添加一个具名标记,并使用当前定位器作为标记上下文。 -Pass `options.stack` to override the callsite location in trace metadata. This is useful for wrapper libraries that need to preserve the end-user source location. +传入 `options.stack` 以覆盖追踪元数据中的调用位置。适用于二次封装库并且需要保留用户调用源码位置的场景。 ```ts import { page } from 'vitest/browser' @@ -865,7 +865,7 @@ await submitButton.mark('after submit') ``` ::: tip -This method is useful only when [`browser.trace`](/config/browser/trace) is enabled. +此方法适用于启用 [`browser.trace`](/config/browser/trace) 配置时有效。 ::: ### query @@ -878,10 +878,8 @@ function query(): Element | null 如果多个元素匹配该选择器,此方法将抛出错误。如果你需要所有匹配的 DOM 元素,可以使用 [`.elements()`](#elements);如果你需要匹配选择器的定位器数组,可以使用 [`.all()`](#all)。 - - ::: danger -This is an escape hatch for external APIs that do not support locators. Prefer using locator methods instead. +这是针对不支持定位器的外部 API 的变通方案。优先使用定位器方法。 ::: 考虑以下 DOM 结构: @@ -1109,7 +1107,7 @@ page.getByRole('alert').length // ✅ 0 ## 自定义定位器 3.2.0 advanced {#custom-locators} -您可以通过定义定位器工厂对象来扩展内置定位器 API。这些方法将作为 `page` 对象和所有已创建定位器的方法存在。 +你可以通过定义定位器工厂对象来扩展内置定位器 API。这些方法将作为 `page` 对象和所有已创建定位器的方法存在。 当内置定位器无法满足需求时(例如使用自定义 UI 框架时),这些定位器会非常有用。 diff --git a/api/browser/svelte.md b/api/browser/svelte.md index 119146249..db9d826dd 100644 --- a/api/browser/svelte.md +++ b/api/browser/svelte.md @@ -216,7 +216,7 @@ await expect.element( ## 代码片段 {#snippets} -对于简单的代码片段,您可以使用包装组件和 “占位” 子元素进行测试。通过设置 `data-testid` 属性帮助测试插槽内容。 +对于简单的代码片段,你可以使用包装组件和 “占位” 子元素进行测试。通过设置 `data-testid` 属性帮助测试插槽内容。 ::: code-group ```ts [basic.test.js] diff --git a/api/browser/vue.md b/api/browser/vue.md index 5cab3cfa4..155a660f1 100644 --- a/api/browser/vue.md +++ b/api/browser/vue.md @@ -161,11 +161,11 @@ rerender({ number: 2 }) ```ts function unmount(): void & PromiseLike ``` - -This will cause the rendered component to be unmounted. Also records a `vue.unmount` trace mark in the [Trace View](/guide/browser/trace-view). This is useful for testing what happens when your component is removed from the page (like testing that you don't leave event handlers hanging around causing memory leaks). + +该操作会触发组件卸载,同时在 [跟踪视图](/guide/browser/trace-view) 中记录 `vue.unmount` 标记点。此功能特别适用于测试组件从页面移除时的行为(例如验证是否残留事件处理器导致内存泄漏)。 ::: warning -Synchronous usage of `unmount` is deprecated and will be removed in the next major version. Please always `await` the result. +同步调用 `unmount` 的方式已被弃用,将在下一主要版本中移除。请使用 `await` 进行异步调用。 ::: #### emitted diff --git a/api/expect.md b/api/expect.md index 418fee79c..ff4da1307 100644 --- a/api/expect.md +++ b/api/expect.md @@ -1356,7 +1356,7 @@ test('spy function resolved a value two times', async () => { - **类型:** `(returnValue: any) => Awaitable` -您可以调用此断言来检查函数是否至少成功解析过一次某个值。需要将 spy 函数传递给`expect`。 +你可以调用此断言来检查函数是否至少成功解析过一次某个值。需要将 spy 函数传递给`expect`。 如果函数返回了一个 promise,但尚未 resolved,则将会失败。 @@ -1376,7 +1376,7 @@ test('spy function resolved a product', async () => { - **类型:** `(returnValue: any) => Awaitable` -您可以调用此断言来检查函数在上次调用时是否已成功解析某个值。需要将 spy 函数传递给`expect`。 +你可以调用此断言来检查函数在上次调用时是否已成功解析某个值。需要将 spy 函数传递给`expect`。 如果函数返回了一个 promise,但尚未 resolved,则将会失败。 diff --git a/config/bail.md b/config/bail.md index 855d23d0b..31fa8754d 100644 --- a/config/bail.md +++ b/config/bail.md @@ -11,4 +11,4 @@ outline: deep 当指定数量的测试用例失败时立即终止测试执行。 -默认情况下,即使部分测试失败,Vitest 仍会继续运行所有测试用例。对于仅关注 100% 成功构建的 CI 环境而言,这种行为可能不符合需求——您可能希望在测试出现失败时尽早终止执行。通过配置 `bail` 选项,可在发生失败时阻止后续测试运行,从而加速 CI 流程。 +默认情况下,即使部分测试失败,Vitest 仍会继续运行所有测试用例。对于仅关注 100% 成功构建的 CI 环境而言,这种行为可能不符合需求——你可能希望在测试出现失败时尽早终止执行。通过配置 `bail` 选项,可在发生失败时阻止后续测试运行,从而加速 CI 流程。 diff --git a/config/browser/preview.md b/config/browser/preview.md index 56534fbc6..509d11837 100644 --- a/config/browser/preview.md +++ b/config/browser/preview.md @@ -20,7 +20,7 @@ export default defineConfig({ }) ``` -这将使用默认浏览器打开一个新的浏览器窗口来运行测试。您可以通过设置 `instances` 数组中的 `browser` 属性来配置使用哪个浏览器。Vitest 会尝试自动打开浏览器,但在某些环境下可能无法正常工作。在这种情况下,您可以在所需的浏览器中手动打开所提供的 URL。 +这将使用默认浏览器打开一个新的浏览器窗口来运行测试。你可以通过设置 `instances` 数组中的 `browser` 属性来配置使用哪个浏览器。Vitest 会尝试自动打开浏览器,但在某些环境下可能无法正常工作。在这种情况下,你可以在所需的浏览器中手动打开所提供的 URL。 ## 与其他 Providers 的差异 diff --git a/config/coverage.md b/config/coverage.md index c3c239490..fcc627c09 100644 --- a/config/coverage.md +++ b/config/coverage.md @@ -132,9 +132,9 @@ npx vitest --coverage.enabled --coverage.provider=istanbul ``` 你可以在 Vitest UI 模式中查看代码覆盖率报告。更多详情请参阅 [Vitest UI Coverage](/guide/coverage#vitest-ui)。 - -::: tip AI coding agents -When Vitest detects it is running inside an AI coding agent, it automatically adds the `text-summary` reporter and sets `skipFull: true` on the `text` reporter to reduce output and minimize token usage. + +::: tip AI 智能体编程 +当 Vitest 检测到运行环境为 AI 智能体编程环境时,会自动启用 `text-summary` 报告器,并对 `text` 报告器设置 `skipFull: true` 以减少输出内容,从而降低令牌消耗。 ::: ## coverage.reportOnFailure {#coverage-reportonfailure} diff --git a/config/css.md b/config/css.md index 05806a871..4c4b80c98 100644 --- a/config/css.md +++ b/config/css.md @@ -41,12 +41,12 @@ outline: deep - **类型:** `'stable' | 'scoped' | 'non-scoped'` - **默认值:** `'stable'` -如果您决定处理 CSS 文件,可以配置 CSS modules 中的类名是否应限定作用域。您可以选择以下选项之一: +如果你决定处理 CSS 文件,可以配置 CSS modules 中的类名是否应限定作用域。你可以选择以下选项之一: - `stable`: 类名将生成为 `_${name}_${hashedFilename}`,这意味着如果 CSS 内容发生变化,生成的类将保持不变,但如果文件名被修改或文件移动到另一个文件夹,则会更改。适用于使用快照功能。 - `scoped`: 类名将照常生成,如果你有 `css.modules.generateScopedName` 方法并且已启用 CSS 处理,则会尊重该方法。默认情况下,文件名将生成为 `_${name}_${hash}`,其中 hash 包含文件名和文件内容。 - `non-scoped`: 类名将不会被哈希。 ::: warning -默认情况下,Vitest 导出一个代理,绕过 CSS 模块处理。如果您依赖类上的 CSS 属性,则必须使用 `include` 选项启用 CSS 处理。 +默认情况下,Vitest 导出一个代理,绕过 CSS 模块处理。如果你依赖类上的 CSS 属性,则必须使用 `include` 选项启用 CSS 处理。 ::: diff --git a/config/experimental.md b/config/experimental.md index 6558f6ea4..c639cf422 100644 --- a/config/experimental.md +++ b/config/experimental.md @@ -378,7 +378,7 @@ const fs = require('node:fs') // 报错 如果你使用的是 Node.js 22.18/23.6 或更高版本,TypeScript 将由 Node.js [原生支持转换](https://nodejs.org/en/learn/typescript/run-natively)。 ::: warning 在 Node.js 22.6-22.18 环境中的使用 TypeScript -如果您使用的 Node.js 版本介于 22.6 至 22.18 之间,还可通过 `--experimental-strip-types` 参数启用原生 TypeScript 支持: +如果你使用的 Node.js 版本介于 22.6 至 22.18 之间,还可通过 `--experimental-strip-types` 参数启用原生 TypeScript 支持: ```shell NODE_OPTIONS="--experimental-strip-types" vitest @@ -481,8 +481,8 @@ export default { ## experimental.preParse 4.1.3 {#experimental-preparse} -- **Type:** `boolean` -- **Default:** `false` +- **类型:** `boolean` +- **默认值:** `false` Parses test specifications before running them. This applies the [`.only`](/api/test#test-only) modifier, the [`-t`](/config/testnamepattern) test name pattern, [`--tags-filter`](/guide/test-tags#syntax), [test lines](/api/advanced/test-specification#testlines), and [test IDs](/api/advanced/test-specification#testids) across all files without executing them. For example, if only a single test is marked with `.only`, Vitest will skip all other tests in all files. diff --git a/config/file.md b/config/file.md index bc4a239a9..83e4c89d3 100644 --- a/config/file.md +++ b/config/file.md @@ -25,7 +25,7 @@ export default defineConfig({ }) ``` -`` 将在 Vitest 3 中停止工作,但您可以在 Vitest 2.1 中开始迁移到 `vitest/config`: +`` 将在 Vitest 3 中停止工作,但你可以在 Vitest 2.1 中开始迁移到 `vitest/config`: ```ts /// diff --git a/config/index.md b/config/index.md index 8868207bc..d9fbbcd98 100644 --- a/config/index.md +++ b/config/index.md @@ -78,11 +78,11 @@ export default defineConfig(configEnv => mergeConfig( ``` 由于 Vitest 使用 Vite 的配置,我们也可以使用 [Vite](https://vitejs.dev/config/) 中的任何配置选项。例如,使用 `define` 来定义全局变量,或者使用 `resolve.alias` 来定义别名——这些选项应该在顶级定义,而不是在 `test` 属性内部。 - -## Automatic Dependency Installation -Vitest will prompt you to install certain dependencies if they are not already installed. You can disable this behavior by setting the `VITEST_SKIP_INSTALL_CHECKS=1` environment variable. +## 自动依赖安装 {#automatic-dependency-installation} -## Config Options +当检测到必要依赖未安装时,Vitest 将提示你进行安装。如需禁用此功能,可通过设置环境变量 `VITEST_SKIP_INSTALL_CHECKS=1` 实现。 + +## 配置选项 {#config-options} 在 [项目](/guide/projects) 配置中不支持的配置选项旁边会显示 图标。这意味着它们只能在 Vitest 根配置文件中进行设置。 diff --git a/config/snapshotformat.md b/config/snapshotformat.md index 48d630a3a..1eead7043 100644 --- a/config/snapshotformat.md +++ b/config/snapshotformat.md @@ -11,7 +11,7 @@ outline: deep 关于 `PrettyFormatOptions` 的完整选项说明,请参阅 [`@vitest/pretty-format`](https://npmx.dev/package/@vitest/pretty-format)。本文档重点介绍 Vitest 快照特有的默认值和限制。 -Vitest 快照在应用您的 `snapshotFormat` 覆盖前已预设以下默认值: +Vitest 快照在应用你的 `snapshotFormat` 覆盖前已预设以下默认值: - `printBasicPrototype: false` - `escapeString: false` diff --git a/config/ui.md b/config/ui.md index 00fd3130c..f07128921 100644 --- a/config/ui.md +++ b/config/ui.md @@ -16,5 +16,5 @@ outline: deep ::: ::: danger 安全警告 -请确保您的 UI 模式的服务不暴露在公共网络中。自 Vitest 4.1 起,出于安全考虑,若将 [`api.host`](/config/api) 设置为非 `localhost` 地址,将自动禁用代码保存和测试运行按钮,使 UI 模式变为只读模式。 +请确保你的 UI 模式的服务不暴露在公共网络中。自 Vitest 4.1 起,出于安全考虑,若将 [`api.host`](/config/api) 设置为非 `localhost` 地址,将自动禁用代码保存和测试运行按钮,使 UI 模式变为只读模式。 ::: diff --git a/guide/advanced/tests.md b/guide/advanced/tests.md index 1f6e24533..0086053e0 100644 --- a/guide/advanced/tests.md +++ b/guide/advanced/tests.md @@ -1,7 +1,7 @@ # 运行测试 advanced {#running-tests} ::: warning 注意 -本指南介绍如何使用高级 API 通过 Node.js 脚本运行测试。如果您只想[运行测试](/guide/),则可能不需要这个。它主要被库的作者使用。 +本指南介绍如何使用高级 API 通过 Node.js 脚本运行测试。如果你只想[运行测试](/guide/),则可能不需要这个。它主要被库的作者使用。 破坏性变更可能不会遵循 SemVer,请在使用实验性 API 时固定 Vitest 的版本。 ::: diff --git a/guide/browser/trace-view.md b/guide/browser/trace-view.md index cf0ca93e4..bcecd84a3 100644 --- a/guide/browser/trace-view.md +++ b/guide/browser/trace-view.md @@ -56,10 +56,10 @@ export default defineConfig({ ``` 追踪文件在报告器中作为 [注释](/guide/test-annotations) 形式呈现。例如,在 HTML 报告器中,你可以在测试详情页中找到追踪文件的链接。 - -## Trace markers -You can add explicit named markers to make the trace timeline easier to read: +## 跟踪标记 {#trace-markers} + +你可以添加具名标记,让追踪时间线更易于阅读: ```ts import { page } from 'vitest/browser' @@ -71,9 +71,9 @@ document.body.innerHTML = ` await page.getByRole('button', { name: 'Sign in' }).mark('sign in button rendered') ``` -Both `page.mark(name)` and `locator.mark(name)` are available. +`page.mark(name)` 和 `locator.mark(name)` 均可用。 -You can also group multiple operations under one marker with `page.mark(name, callback)`: +你还可以使用 `page.mark(name, callback)` 将多个操作归到同一标记下: ```ts await page.mark('sign in flow', async () => { @@ -83,7 +83,7 @@ await page.mark('sign in flow', async () => { }) ``` -You can also wrap reusable helpers with [`vi.defineHelper()`](/api/vi#vi-defineHelper) so trace entries point to where the helper is called, not its internals: +你也可以用 [`vi.defineHelper()`](/api/vi#vi-defineHelper) 包装可复用的工具函数,这样追踪条目会指向调用该函数的位置,而非其内部: ```ts import { vi } from 'vitest' @@ -95,7 +95,7 @@ const myRender = vi.defineHelper(async (content: string) => { }) test('renders content', async () => { - await myRender('') // trace points to this line + await myRender('') // 追踪指向这一行 }) ``` @@ -117,12 +117,12 @@ npx playwright show-trace "path-to-trace-file" ## 局限性 {#limitations} 目前,Vitest 无法填充 Trace Viewer 中的 "Sources" 标签页。这意味着虽然你可以看到测试期间捕获的操作和截图,但无法直接在 Trace Viewer 中查看测试的源代码。你需要返回代码编辑器查看测试实现。 - -- `expect.element(...)` assertions -- Interactive actions like `click`, `fill`, `type`, `hover`, `selectOptions`, `upload`, `dragAndDrop`, `tab`, `keyboard`, `wheel`, and screenshots -Under the hood, Playwright still records its own low-level action events as usual. Vitest wraps them with source-location groups so you can jump straight from the trace timeline to the relevant line in your test. +- `expect.element(...)` 断言方法 +- 交互操作如 `click`, `fill`, `type`, `hover`, `selectOptions`, `upload`, `dragAndDrop`, `tab`, `keyboard`, `wheel` 以及屏幕截图 + +底层实现上,Playwright 仍会照常记录其原始操作事件。Vitest 通过源码定位分组对这些事件进行封装,使你可以直接从跟踪时间轴跳转到测试代码的对应行。 -Keep in mind that plain assertions like `expect(value).toBe(...)` run in Node, not the browser, so they won't show up in the trace. +需注意,像 `expect(value).toBe(...)` 这样的常规断言是在 Node 中运行的,而不是在浏览器中运行,因此它们不会出现在追踪中。 -For anything not covered automatically, you can use `page.mark()` or `locator.mark()` to add your own trace groups — see [Trace markers](#trace-markers) above. +对于任何未自动覆盖的内容,你可以使用 `page.mark()` 或 `locator.mark()` 添加自定义跟踪分组,详见前文 [跟踪标记](#trace-markers) 章节。 diff --git a/guide/cli-generated.md b/guide/cli-generated.md index 727ab5619..829934384 100644 --- a/guide/cli-generated.md +++ b/guide/cli-generated.md @@ -427,35 +427,35 @@ Directory of HTML coverage output to be served in UI mode and HTML reporter. - **命令行终端:** `--browser.trace ` - **配置:** [browser.trace](/config/browser/trace) -启用追踪视图模式。 可选项: "on", "off", "on-first-retry", "on-all-retries", "retain-on-failure" - +启用追踪视图模式。可选项: "on", "off", "on-first-retry", "on-all-retries", "retain-on-failure" + ### browser.locators.exact -- **CLI:** `--browser.locators.exact` -- **Config:** [browser.locators.exact](/config/browser/locators#locators-exact) +- **命令行终端:** `--browser.locators.exact` +- **配置:** [browser.locators.exact](/config/browser/locators#locators-exact) -Should locators match the text exactly by default (default: `false`) +定位器是否默认需完全匹配文本内容(默认值:`false`) ### pool - **命令行终端:** `--pool ` - **配置:** [pool](/config/pool) -如果未在浏览器中运行,则指定 pool (默认值: `threads`) +如果未在浏览器中运行,则指定 pool (默认值: `threads`)。 ### execArgv - **命令行终端:** `--execArgv