diff --git a/config/index.md b/config/index.md index 0fa77688..4e220580 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. +>>>>>>> 78ee2995b40ef9f8e295c810946ab9b4e3690b6c 如果你尚未使用 `vite` ,可以在配置文件中从 `vitest/config` 导入 `defineConfig`: diff --git a/guide/browser/why.md b/guide/browser/why.md index 57185e3b..4dae5ae2 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. +>>>>>>> 78ee2995b40ef9f8e295c810946ab9b4e3690b6c Vitest 浏览器在初始化过程中需要启动提供程序和浏览器,这可能需要一些时间。与其他测试模式相比,这可能导致更长的初始化时间。 diff --git a/guide/learn/writing-tests.md b/guide/learn/writing-tests.md index e579ada4..c821d13e 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. +>>>>>>> 78ee2995b40ef9f8e295c810946ab9b4e3690b6c 如果你的用例包含两个或三个以上的值,传递对象更具可读性。在名称中使用 `$property` 来插入字段: diff --git a/guide/migration.md b/guide/migration.md index f2283d1c..b16e807e 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} +>>>>>>> 78ee2995b40ef9f8e295c810946ab9b4e3690b6c ::: warning 前提条件 Vitest 4.0 要求 **Vite >= 6.0.0** 和 **Node.js >= 20.0.0**。