Skip to content
Closed
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/runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export interface VitestRunner {
/**
* 公开可用的配置。
*/
config: VitestRunnerConfig
config: SerializedConfig
/**
* 当前池的名称。可能会影响服务器端如何推断堆栈跟踪。
*/
Expand Down
4 changes: 4 additions & 0 deletions api/advanced/vitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
公共 `state` 是一个实验性 API(除了 `vitest.state.getReportedEntity`)。破坏性更改可能不遵循 SemVer,请在使用时固定 Vitest 的版本。
:::

<<<<<<< HEAD

Check failure on line 30 in api/advanced/vitest.md

View workflow job for this annotation

GitHub Actions / autofix

Unexpected additional H1 heading found
全局状态存储有关当前测试的信息。默认情况下,它使用与 `@vitest/runner` 相同的 API,但我们建议通过调用 `@vitest/runner` API 上的 `state.getReportedEntity()` 来使用 [任务报告器 API](/api/advanced/reporters#reported-tasks):
=======
Global state stores information about the current tests. It uses internal serializable Task API by default, but we recommend using the [Reported Tasks API](/api/advanced/reporters#reported-tasks) instead by calling `state.getReportedEntity()`:
>>>>>>> fa7b91791854e14250ed1f3538969313d26c7f08

```ts
const task = vitest.state.idMap.get(taskId) // 旧 API
Expand Down
6 changes: 6 additions & 0 deletions config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
- 向 CLI 传递 `--config` 选项,例如 `vitest --config ./path/to/vitest.config.ts`。
- 使用 `process.env.VITEST` 或在 `defineConfig` 上的 `mode` 属性(如果没有用 `--mode` 覆盖,默认设置为 `test`)也可以在 `vite.config.ts` 中有条件地应用不同的配置。请注意,像任何其他环境变量一样,`VITEST` 也会在测试中的 `import.meta.env` 上暴露出来。

<<<<<<< HEAD

Check failure on line 13 in config/index.md

View workflow job for this annotation

GitHub Actions / autofix

Unexpected additional H1 heading found

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve leftover merge conflict markers

This commit leaves raw merge-conflict markers in the published Markdown; I checked with rg -n '^(<<<<<<<|=======|>>>>>>>)' and found the same pattern in api/advanced/vitest.md, guide/browser/why.md, guide/learn/writing-tests.md, and guide/migration.md as well. If this is deployed as-is, VitePress will render the markers and both conflicting versions of the text instead of the intended merged Chinese documentation.

Useful? React with 👍 / 👎.

要配置 Vitest 本身,请在我们的 Vite 配置中添加 `test` 属性。如果我们是从 `vite` 本身导入 `defineConfig`,我们还需要在配置文件顶部使用 [三斜杠指令](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-types-) 添加对 Vitest 类型引用。
=======
When an explicit `--config` option is not provided, Vitest looks for `vitest.config.{ts,mts,cts,js,mjs,cjs}` first and `vite.config.{ts,mts,cts,js,mjs,cjs}` second in the project [`root`](/config/root). If no config file is found, Vitest will run without one.

To configure `vitest` itself, add `test` property in your Vite config. You'll also need to add a reference to Vitest types using a [triple slash command](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-types-) at the top of your config file, if you are importing `defineConfig` from `vite` itself.
>>>>>>> fa7b91791854e14250ed1f3538969313d26c7f08

如果你尚未使用 `vite` ,可以在配置文件中从 `vitest/config` 导入 `defineConfig`:

Expand Down
6 changes: 6 additions & 0 deletions guide/browser/why.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ outline: deep

### 早期开发 {#early-development}

<<<<<<< HEAD
Vitest 的浏览器模式功能仍处于早期开发阶段。因此,它可能尚未完全优化,可能存在一些尚未解决的错误或问题。建议用户使用独立的浏览器端测试运行程序(如 WebdriverIO、Cypress 或 Playwright)来增强 Vitest 浏览器体验。

### 更长的初始化时间 {#longer-initialization}
=======
### Not a Drop-In Replacement

The browser mode feature of Vitest does not completely replace standalone end-to-end test runners. It is recommended that users augment their Vitest browser experience with a standalone browser-side test runner like WebdriverIO, Cypress or Playwright.
>>>>>>> fa7b91791854e14250ed1f3538969313d26c7f08

Vitest 浏览器在初始化过程中需要启动提供程序和浏览器,这可能需要一些时间。与其他测试模式相比,这可能导致更长的初始化时间。
4 changes: 4 additions & 0 deletions guide/learn/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@
})
```

<<<<<<< HEAD

Check failure on line 179 in guide/learn/writing-tests.md

View workflow job for this annotation

GitHub Actions / autofix

Unexpected additional H1 heading found
测试名称中的占位符 `%i`、`%s` 和 `%f` 会被每行中对应的值替换,因此输出会显示 `add(1, 1) -> 2`、`add(1, 2) -> 3` 等。
=======
In the example above, the %i placeholders are replaced with the integer values from each data row. Vitest also supports other placeholder types, such as %s for strings and %f for floating-point numbers. As a result, the test runner generates test names such as add(1, 1) -> 2, add(1, 2) -> 3, and add(2, 1) -> 3.
>>>>>>> fa7b91791854e14250ed1f3538969313d26c7f08

如果你的用例包含两个或三个以上的值,传递对象更具可读性。在名称中使用 `$property` 来插入字段:

Expand Down
13 changes: 13 additions & 0 deletions guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,20 @@ await expect.element(banner).toMatchTextContent(/error/i) // [!code ++]
await expect.element(banner).toHaveTextContent('Error!')
```

<<<<<<< HEAD
## 迁移至 Vitest 4.0 {#vitest-4}
=======
### Config Files Are Not Looked Up From Parent Directories

Vitest no longer searches parent directories for config files. If you previously relied on running `vitest` from a subdirectory while using a config file from a parent directory, pass the config explicitly and scope test discovery with `--dir`. For example,

```bash
$ cd subdir && vitest # [!code --]
$ cd subdir && vitest --config ../vitest.config.ts # [!code ++]
```

## Migrating to Vitest 4.0 {#vitest-4}
>>>>>>> fa7b91791854e14250ed1f3538969313d26c7f08

::: warning 前提条件
Vitest 4.0 要求 **Vite >= 6.0.0** 和 **Node.js >= 20.0.0**。
Expand Down
Loading