diff --git a/api/advanced/runner.md b/api/advanced/runner.md index b820da6c..ab31176a 100644 --- a/api/advanced/runner.md +++ b/api/advanced/runner.md @@ -98,7 +98,7 @@ export interface VitestRunner { /** * 公开可用的配置。 */ - config: VitestRunnerConfig + config: SerializedConfig /** * 当前池的名称。可能会影响服务器端如何推断堆栈跟踪。 */ diff --git a/api/advanced/vitest.md b/api/advanced/vitest.md index 4f456a71..201a2ad3 100644 --- a/api/advanced/vitest.md +++ b/api/advanced/vitest.md @@ -27,7 +27,11 @@ Since Vitest 5, this property is always `'test'`. 公共 `state` 是一个实验性 API(除了 `vitest.state.getReportedEntity`)。破坏性更改可能不遵循 SemVer,请在使用时固定 Vitest 的版本。 ::: +<<<<<<< HEAD 全局状态存储有关当前测试的信息。默认情况下,它使用与 `@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 diff --git a/config/index.md b/config/index.md index 0fa77688..958eeb93 100644 --- a/config/index.md +++ b/config/index.md @@ -10,7 +10,13 @@ outline: deep - 向 CLI 传递 `--config` 选项,例如 `vitest --config ./path/to/vitest.config.ts`。 - 使用 `process.env.VITEST` 或在 `defineConfig` 上的 `mode` 属性(如果没有用 `--mode` 覆盖,默认设置为 `test`)也可以在 `vite.config.ts` 中有条件地应用不同的配置。请注意,像任何其他环境变量一样,`VITEST` 也会在测试中的 `import.meta.env` 上暴露出来。 +<<<<<<< HEAD 要配置 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`: diff --git a/guide/browser/why.md b/guide/browser/why.md index 57185e3b..62b8ee1e 100644 --- a/guide/browser/why.md +++ b/guide/browser/why.md @@ -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 浏览器在初始化过程中需要启动提供程序和浏览器,这可能需要一些时间。与其他测试模式相比,这可能导致更长的初始化时间。 diff --git a/guide/learn/writing-tests.md b/guide/learn/writing-tests.md index e579ada4..7af501fa 100644 --- a/guide/learn/writing-tests.md +++ b/guide/learn/writing-tests.md @@ -176,7 +176,11 @@ test.for([ }) ``` +<<<<<<< HEAD 测试名称中的占位符 `%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` 来插入字段: diff --git a/guide/migration.md b/guide/migration.md index f2283d1c..527e04d2 100644 --- a/guide/migration.md +++ b/guide/migration.md @@ -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**。