Skip to content

docs(en): merge docs-cn/sync-docs into docs-cn/dev @ f87bb8ef #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 37 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6f3d705
fix(deps): update all non-major dependencies (#7867)
renovate[bot] Apr 24, 2025
2905288
docs: fix typo (#7886)
Elijer Apr 24, 2025
43966ff
docs: deprecate old context augmentation and recommend test.extend (#…
sheremet-va May 2, 2025
aecfe2c
fix(browser): resolve FS commands relative to the project root (#7896)
sheremet-va May 5, 2025
4f3f3a1
feat: provide `ctx.signal` (#7878)
sheremet-va May 5, 2025
2fd4f42
feat(coverage): v8 experimental AST-aware remapping (#7736)
AriPerkkio May 5, 2025
9a5874b
feat: support custom colors for `test.name` (#7809)
AriPerkkio May 5, 2025
8706c77
feat: add `vi.mockObject` to automock any object (#7761)
hi-ogawa May 5, 2025
0b7a91c
feat(browser): implement `connect` option for `playwright` browser pr…
egfx-notifications May 5, 2025
5c80186
feat: introduce `watchTriggerPatterns` option (#7778)
sheremet-va May 5, 2025
dd5596a
docs: fix example
sheremet-va May 5, 2025
a40aa27
docs: use `extends` instead of `configFile` in `injectTestProjects` (…
romhml May 5, 2025
e906203
feat: deprecate `workspace` in favor of `projects` (#7923)
sheremet-va May 5, 2025
69ccc6e
chore(snapshots): rename `message` to `hint` in method signatures (#7…
k-yle May 6, 2025
8f0fb8c
docs: fix toEqualTypeOf in testing-types.md (#7938)
tkrotoff May 6, 2025
823cf17
docs: minor prose improvements to it.for documentation (#7956)
berzi May 11, 2025
7eae51c
fix: try to catch unhandled error outside of a test (#7968)
sheremet-va May 13, 2025
1381b9a
docs: typos in `docs/guide/browser/index.md` (#7983)
flx-sta May 15, 2025
614835c
fix(typecheck): avoid creating a temporary tsconfig file when typeche…
sheremet-va May 16, 2025
fba0fad
docs: word about typeRoots for typescript configuration (#7977)
anaelChardan May 17, 2025
8da2f8a
docs: add "Parallelism" guide (#7975)
sheremet-va May 17, 2025
6eea07a
fix(cli): add built-in reporters list to --help output (#7955)
pengooseDev May 17, 2025
60e13c7
docs: fix config filename for Production build section (#7926)
gwennlbh May 17, 2025
3fbd5a6
feat: Explicit Resource Management support in mocked functions (#7927)
EskiMojo14 May 17, 2025
e6b8863
feat(browser): add `screenshot.save` option (#7777)
sheremet-va May 17, 2025
da91a4b
docs: update version
sheremet-va May 17, 2025
6ee6272
docs: update version
sheremet-va May 17, 2025
f6ba233
feat: add `sequence.groupOrder` option (#7852)
sheremet-va May 17, 2025
f9275a5
feat(browser): custom locators API (#7993)
sheremet-va May 17, 2025
f6d1a2a
fix(expect): support type-safe declaration of custom matchers (#7656)
kettanaito May 19, 2025
c0af384
fix: throw an error if typechecker failed to spawn (#7990)
sheremet-va May 19, 2025
ab271bb
docs: update the browser CLI option
sheremet-va May 19, 2025
e105a94
chore(deps): update all non-major dependencies (#7929)
renovate[bot] May 20, 2025
8472a67
docs: fix typo (#8011)
MichaHuhn May 23, 2025
c2c8aa7
docs: fix typo, improve formatting (#8025)
ansgarprause May 26, 2025
f87bb8e
feat(reporter): add `onWritePath` option to `github-actions` (#8015)
nwalters512 May 26, 2025
9e41067
docs(en): merging all conflicts
docschina-bot May 26, 2025
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
30 changes: 30 additions & 0 deletions .vitepress/components/FeaturesList.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
<template>
<<<<<<< HEAD
<ul class="features-list" dir="auto" flex="~ col gap2 md:gap-3">
=======
<ul
class="features-list"
dir="auto"
flex="~ col gap2 md:gap-3"
>
<ListItem><a target="_blank" href="https://vitejs.dev" rel="noopener noreferrer">Vite</a>'s config, transformers, resolvers, and plugins</ListItem>
<ListItem>Use the same setup from your app to run the tests!</ListItem>
<ListItem>Smart & instant watch mode, like HMR for tests!</ListItem>
<ListItem>Component testing for Vue, React, Svelte, Lit, Marko and more</ListItem>
<ListItem>Out-of-the-box TypeScript / JSX support</ListItem>
<ListItem>ESM first, top level await</ListItem>
<ListItem>Workers multi-threading via <a target="_blank" href="https://github.com/tinylibs/tinypool" rel="noopener noreferrer">Tinypool</a></ListItem>
<ListItem>Benchmarking support with <a target="_blank" href="https://github.com/tinylibs/tinybench" rel="noopener noreferrer">Tinybench</a></ListItem>
<ListItem>Filtering, timeouts, concurrent for suite and tests</ListItem>
<ListItem><a href="/guide/projects">Projects</a> support</ListItem>
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
<ListItem>
<a target="_blank" href="https://vitejs.dev" rel="noopener noreferrer">Vite</a>
通用的配置、转换器、解析器和插件。
</ListItem>
<<<<<<< HEAD
<ListItem>使用与你的应用相同的设置来运行测试!</ListItem>
<ListItem>智能文件监听模式,就像是测试的 HMR!</ListItem>
<ListItem>支持对 Vue、React、Svelte、Lit等框架进行组件测试。</ListItem>
Expand Down Expand Up @@ -82,6 +101,17 @@
进行类型测试
</ListItem>
<ListItem>支持分片</ListItem>
=======
<ListItem><a target="_blank" href="https://www.chaijs.com/" rel="noopener noreferrer">Chai</a> built-in for assertions + <a target="_blank" href="https://jestjs.io/docs/expect" rel="noopener noreferrer">Jest expect</a> compatible APIs</ListItem>
<ListItem><a target="_blank" href="https://github.com/tinylibs/tinyspy" rel="noopener noreferrer">Tinyspy</a> built-in for mocking</ListItem>
<ListItem><a target="_blank" href="https://github.com/capricorn86/happy-dom" rel="noopener noreferrer">happy-dom</a> or <a target="_blank" href="https://github.com/jsdom/jsdom" rel="noopener noreferrer">jsdom</a> for DOM mocking</ListItem>
<ListItem><a href="https://vitest.dev/guide/browser/" rel="noopener noreferrer">Browser Mode</a> for running component tests in the browser</ListItem>
<ListItem>Code coverage via <a target="_blank" href="https://v8.dev/blog/javascript-code-coverage" rel="noopener noreferrer">v8</a> or <a target="_blank" href="https://istanbul.js.org/" rel="noopener noreferrer">istanbul</a></ListItem>
<ListItem>Rust-like <a href="/guide/in-source">in-source testing</a></ListItem>
<ListItem>Type Testing via <a target="_blank" href="https://github.com/mmkal/expect-type" rel="noopener noreferrer">expect-type</a></ListItem>
<ListItem>Sharding Support</ListItem>
<ListItem>Reporting Uncaught Errors</ListItem>
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
</ul>
</template>

Expand Down
13 changes: 13 additions & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,13 @@ function guide(): DefaultTheme.SidebarItem[] {
link: '/guide/filtering',
},
{
<<<<<<< HEAD
text: '工作空间',
link: '/guide/workspace',
=======
text: 'Test Projects',
link: '/guide/projects',
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
},
{
text: '报告器「Reporters」',
Expand All @@ -489,7 +494,15 @@ function guide(): DefaultTheme.SidebarItem[] {
link: '/guide/mocking',
},
{
<<<<<<< HEAD
text: '类型测试',
=======
text: 'Parallelism',
link: '/guide/parallelism',
},
{
text: 'Testing Types',
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
link: '/guide/testing-types',
},
{
Expand Down
4 changes: 4 additions & 0 deletions advanced/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ const { vitestConfig, viteConfig } = await resolveConfig({
:::

::: warning
<<<<<<< HEAD
`resolveConfig` 不会解析 `workspace`。要解析工作区配置,Vitest 需要一个已建立的 Vite 服务器。
=======
The `resolveConfig` doesn't resolve `projects`. To resolve projects configs, Vitest needs an established Vite server.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d

另外请注意,`viteConfig.test` 不会被完全解析。如果你需要 Vitest 配置,请使用 `vitestConfig` 代替。
:::
Expand Down
16 changes: 14 additions & 2 deletions advanced/api/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ Vitest 通过 `Vite` namespace 重新导出所有仅 Vite 类型的导入,我
```
:::

<<<<<<< HEAD
与 [`reporter.onInit`](/advanced/api/reporters#oninit) 不同,此 hooks 在 Vitest 生命周期的早期运行,允许我们更改 `coverage` 和 `reporters` 等配置。更值得注意的变化是,如果我们的插件是在项目中定义而不是在全局配置中定义的,我们可以从 [工作区项目](/guide/workspace) 操作全局配置。
=======
Unlike [`reporter.onInit`](/advanced/api/reporters#oninit), this hooks runs early in Vitest lifecycle allowing you to make changes to configuration like `coverage` and `reporters`. A more notable change is that you can manipulate the global config from a [test project](/guide/projects) if your plugin is defined in the project and not in the global config.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d

## Context

Expand Down Expand Up @@ -93,10 +97,10 @@ function injectTestProjects(
```ts
// inject a single project with a custom alias
const newProjects = await injectTestProjects({
// you can inherit the current project config by referencing `configFile`
// you can inherit the current project config by referencing `extends`
// note that you cannot have a project with the name that already exists,
// so it's a good practice to define a custom name
configFile: project.vite.config.configFile,
extends: project.vite.config.configFile,
test: {
name: 'my-custom-alias',
alias: {
Expand All @@ -107,7 +111,11 @@ const newProjects = await injectTestProjects({
```

::: warning Projects are Filtered
<<<<<<< HEAD
Vitest 在配置解析期间过滤项目,因此如果用户定义了过滤器,则注入的项目可能无法解析,除非它 [与 filter 匹配](./vitest#matchesprojectfilter)。我们可以通过 `vitest.config.project` 选项更新过滤器,以始终包含我们的工作区项目:
=======
Vitest filters projects during the config resolution, so if the user defined a filter, injected project might not be resolved unless it [matches the filter](./vitest#matchesprojectfilter). You can update the filter via the `vitest.config.project` option to always include your test project:
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d

```ts
vitest.config.project.push('my-project-name')
Expand All @@ -117,7 +125,11 @@ vitest.config.project.push('my-project-name')
:::

::: tip Referencing the Current Config
<<<<<<< HEAD
如果我们想保留用户配置,可以指定 `configFile` 属性。所有其他属性都将与用户定义的配置合并。
=======
If you want to keep the user configuration, you can specify the `extends` property. All other properties will be merged with the user defined config.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d

项目的 `configFile` 可以在 Vite 的配置中访问:`project.vite.config.configFile`。

Expand Down
45 changes: 45 additions & 0 deletions advanced/api/test-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ title: TestProject

# TestProject <Version>3.0.0</Version> {#testproject}

<<<<<<< HEAD
- **别名**:在 3.0.0 之前称为 `WorkspaceProject`

::: warning
本指南描述了高级的 Node.js API。如果我们只是想创建一个工作区,请遵循 [Workspace](/guide/workspace) 指南。
=======
::: warning
This guide describes the advanced Node.js API. If you just want to define projects, follow the ["Test Projects"](/guide/projects) guide.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
:::

## name
Expand All @@ -26,6 +31,7 @@ vitest.projects.map(p => p.name) === [
'custom'
]
```
<<<<<<< HEAD
```ts [vitest.workspace.js]
export default [
'./packages/server', // 有 package.json,名称为 "@pkg/server"
Expand All @@ -43,11 +49,40 @@ export default [
},
},
]
=======
```ts [vitest.config.js]
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
projects: [
'./packages/server', // has package.json with "@pkg/server"
'./utils', // doesn't have a package.json file
{
// doesn't customize the name
test: {
pool: 'threads',
},
},
{
// customized the name
test: {
name: 'custom',
},
},
],
},
})
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
```
:::

::: info
<<<<<<< HEAD
如果 [根项目](/advanced/api/vitest#getroottestproject) 不是用户工作区的一部分,则不会解析其 `name`。
=======
If the [root project](/advanced/api/vitest#getroottestproject) is not part of user projects, its `name` will not be resolved.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
:::

## vitest
Expand Down Expand Up @@ -86,6 +121,12 @@ vitest.config === vitest.projects[0].globalConfig

这是项目的已解析测试配置。

## hash <Version>3.2.0</Version> {#hash}

The unique hash of this project. This value is consistent between the reruns.

It is based on the root of the project and its name. Note that the root path is not consistent between different OS, so the hash will also be different.

## vite

这是项目的 [`ViteDevServer`](https://vite.dev/guide/api-javascript#vitedevserver)。所有项目都有自己的 Vite 服务器。
Expand Down Expand Up @@ -279,7 +320,11 @@ dynamicExample !== staticExample // ✅
:::

::: info
<<<<<<< HEAD
在内部,Vitest 使用此方法导入全局设置、自定义覆盖率提供者、工作区文件和自定义报告器,这意味着只要它们属于同一个 Vite 服务器,它们就共享相同的模块图。
=======
Internally, Vitest uses this method to import global setups, custom coverage providers and custom reporters, meaning all of them share the same module graph as long as they belong to the same Vite server.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
:::

## onTestsRerun
Expand Down
18 changes: 18 additions & 0 deletions advanced/api/vitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ Vitest 3 在稳定公共 API 方面迈出了一步。为了实现这一点,我

## config

<<<<<<< HEAD
根(或全局)配置。如果启用了工作区功能,项目将引用此配置作为 `globalConfig`。
=======
The root (or global) config. If projects are defined, they will reference this as `globalConfig`.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d

::: warning
这是 Vitest 配置,它不扩展 _Vite_ 配置。它仅包含从 `test` 属性解析的值。
Expand Down Expand Up @@ -101,17 +105,27 @@ const testCase = vitest.state.getReportedEntity(task) // 新 API

## projects

<<<<<<< HEAD
属于用户工作区的 [测试项目](/advanced/api/test-project) 数组。如果用户未指定自定义工作区,则工作区将仅包含一个 [根项目](#getrootproject)。

Vitest 将确保工作区中始终至少有一个项目。如果用户指定了不存在的 `--project` 名称,Vitest 将抛出错误。
=======
An array of [test projects](/advanced/api/test-project) that belong to user's projects. If the user did not specify a them, this array will only contain a [root project](#getrootproject).

Vitest will ensure that there is always at least one project in this array. If the user specifies a non-existent `--project` name, Vitest will throw an error before this array is defined.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d

## getRootProject

```ts
function getRootProject(): TestProject
```

<<<<<<< HEAD
返回根测试项目。根项目通常不运行任何测试,并且除非用户明确在其工作区中包含根配置,或者根本没有定义工作区,否则不会包含在 `vitest.projects` 中。
=======
This returns the root test project. The root project generally doesn't run any tests and is not included in `vitest.projects` unless the user explicitly includes the root config in their configuration, or projects are not defined at all.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d

根项目的主要目标是设置全局配置。实际上,`rootProject.config` 直接引用 `rootProject.globalConfig` 和 `vitest.config`:

Expand Down Expand Up @@ -433,7 +447,11 @@ dynamicExample !== staticExample // ✅
:::

::: info
<<<<<<< HEAD
在内部,Vitest 使用此方法导入全局设置、自定义覆盖率提供者、工作区文件和自定义报告器,这意味着只要它们属于同一个 Vite 服务器,它们就共享相同的模块图。
=======
Internally, Vitest uses this method to import global setups, custom coverage providers, and custom reporters, meaning all of them share the same module graph as long as they belong to the same Vite server.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
:::

## close
Expand Down
13 changes: 12 additions & 1 deletion advanced/pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ export default defineConfig({
})
```

<<<<<<< HEAD
如果我们在不同 pools 中运行测试,可以使用 [workspace](/guide/workspace) 功能:
=======
If you need to run tests in different pools, use the [`projects`](/guide/projects) feature:
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d

```ts [vitest.config.ts]
export default defineConfig({
test: {
workspace: [
projects: [
{
extends: true,
test: {
Expand All @@ -48,10 +52,13 @@ export default defineConfig({
})
```

<<<<<<< HEAD
::: info
`workspace` 字段是在 Vitest 3 中引入的。在 [Vitest 2](https://v2.vitest.dev/) 中定义工作区,需要创建一个单独的 `vitest.workspace.ts` 文件。
:::

=======
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
## API

在 `pool` 选项中指定的文件应该导出一个函数(可以是异步的),该函数接受 `Vitest` 接口作为其第一个选项。这个函数需要返回一个与 `ProcessPool` 接口匹配的对象:
Expand All @@ -69,7 +76,11 @@ export interface ProcessPool {

这个函数只会被调用一次(除非服务器配置被更新),通常最好在这个函数内初始化测试所需的一切,并在调用 `runTests` 时重复使用它。

<<<<<<< HEAD
Vitest 在安排运行新测试时调用 `runTest`。如果 `files` 为空,将不会调用它。第一个参数是一个 [TestSpecifications](/advanced/api/test-specification) 数组。在调用 `runTests` 之前,文件将使用 [`sequencer`](/config/#sequence-sequencer) 进行排序。可能(但不太可能)会有相同的文件出现两次,但它们将始终属于不同的项目 - 这是通过 [`vitest.workspace.ts`](/guide/workspace) 配置实现的。
=======
Vitest calls `runTest` when new tests are scheduled to run. It will not call it if `files` is empty. The first argument is an array of [TestSpecifications](/advanced/api/test-specification). Files are sorted using [`sequencer`](/config/#sequence-sequencer) before `runTests` is called. It's possible (but unlikely) to have the same file twice, but it will always have a different project - this is implemented via [`projects`](/guide/projects) configuration.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d

Vitest 会等到 `runTests` 执行完毕后才结束运行(即只有在 `runTests` 解决后才会触发 [`onFinished`](/advanced/reporters))。

Expand Down
8 changes: 8 additions & 0 deletions advanced/runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ interface File extends Suite {
*/
filepath: string
/**
<<<<<<< HEAD
* 文件所属的工作区项目的名称。
=======
* The name of the test project the file belongs to.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
*/
projectName: string | undefined
/**
Expand Down Expand Up @@ -218,7 +222,11 @@ interface Test<ExtraContext = object> extends TaskBase {
*/
file: File
/**
<<<<<<< HEAD
* 任务是否通过调用 `t.skip()` 被跳过。
=======
* Whether the task was skipped by calling `context.skip()`.
>>>>>>> f87bb8ef3299ee7534fc57b579a8e9d62d353f6d
*/
pending?: boolean
/**
Expand Down
Loading