Skip to content

docs(en): merge docs-cn/sync-docs into docs-cn/dev @ 5a793950 #664

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 54 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 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
1fd4ead
chore(deps): update dependency @vite-pwa/vitepress to v1 (#7998)
renovate[bot] May 27, 2025
45ff01e
docs: add `vitest-browser-preact` (#8038)
JoviDeCroock May 27, 2025
d49323b
fix(browser): resolve `upload` files relative to the project root (#8…
sheremet-va May 28, 2025
87980d2
feat: track module execution totalTime and selfTime (#8027)
abrenneke May 29, 2025
73e4e8a
chore: use bolt logo for StackBlitz (#8059)
patak-dev May 30, 2025
0f23235
feat: annotation API (#7953)
sheremet-va May 30, 2025
d42eb26
feat(vitest): allow per-file and per-worker fixtures (#7704)
sheremet-va May 31, 2025
917644c
docs: add blog post for 3.2 (#8001)
sheremet-va Jun 2, 2025
7c7b166
docs(coverage): explain v8 and istanbul differences (#8065)
AriPerkkio Jun 2, 2025
b662ec9
docs: add two more feature to the announcement (#8073)
sheremet-va Jun 2, 2025
343dabb
docs(performance): clarify the way sharding works (#8072)
kettanaito Jun 2, 2025
66a9b6b
docs: remove outdated section (#8066)
DevJoaoLopes Jun 3, 2025
5adb9a6
chore(deps): update dependency @vite-pwa/assets-generator to v1 (#7997)
renovate[bot] Jun 5, 2025
6581578
fix(browser): calculate prepare time from `createTesters` call on the…
sheremet-va Jun 5, 2025
83f9c54
docs(coverage): small typos (#8113)
AriPerkkio Jun 10, 2025
d773ae8
docs: capitalize titles (#8143)
iiio2 Jun 10, 2025
5a79395
docs: Typo in doc for `watchTriggerPatterns` (#8157)
ItsJustRuby Jun 12, 2025
e9007e7
docs(en): merging all conflicts
docschina-bot Jun 13, 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
2 changes: 2 additions & 0 deletions .vitepress/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
ArrowDown: typeof import('./components/ArrowDown.vue')['default']
BlogIndex: typeof import('./components/BlogIndex.vue')['default']
Box: typeof import('./components/Box.vue')['default']
Contributors: typeof import('./components/Contributors.vue')['default']
CourseLink: typeof import('./components/CourseLink.vue')['default']
FeaturesList: typeof import('./components/FeaturesList.vue')['default']
Expand Down
27 changes: 27 additions & 0 deletions .vitepress/components/ArrowDown.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<span class="arrow-down">
<span class="arrow-line" />
<span class="arrow-head" />
</span>
</template>

<style scoped>
.arrow-down {
display: flex;
flex-direction: column;
align-items: center;
}

.arrow-line {
height: 1rem;
width: 0.2rem;
background-color: var(--vp-c-brand-1);
}

.arrow-head {
height: 1rem;
width: 1rem;
background-color: var(--vp-c-brand-1);
clip-path: polygon(100% 0, 0 0, 50% 100%);
}
</style>
18 changes: 18 additions & 0 deletions .vitepress/components/Box.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<span class="box">
<slot />
</span>
</template>

<style scoped>
.box {
display: flex;
width: 100%;
align-items: center;
justify-content: center;
text-align: center;
border: 0.1rem solid var(--vp-c-brand-1);
border-radius: 15px;
padding: 1rem 2rem;
}
</style>
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>
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017
<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>
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017
</ul>
</template>

Expand Down
21 changes: 21 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',
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017
},
{
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',
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017
link: '/guide/testing-types',
},
{
Expand All @@ -505,7 +518,15 @@ function guide(): DefaultTheme.SidebarItem[] {
link: '/guide/test-context',
},
{
<<<<<<< HEAD
text: '测试环境',
=======
text: 'Test Annotations',
link: '/guide/test-annotations',
},
{
text: 'Environment',
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017
link: '/guide/environment',
},
{
Expand Down
6 changes: 3 additions & 3 deletions .vitepress/sponsors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const vitestSponsors = {
img: '/nuxtlabs.svg',
},
{
name: 'Stackblitz',
url: 'https://stackblitz.com',
img: '/stackblitz.svg',
name: 'Bolt',
url: 'https://bolt.new',
img: '/bolt.svg',
},
{
name: 'Zammad',
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.
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017

另外请注意,`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.
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017

## 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:
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017

```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.
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017

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

Expand Down
18 changes: 18 additions & 0 deletions advanced/api/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Vitest 拥有自己的测试运行生命周期。这些生命周期通过报告
- [`onHookStart(beforeAll)`](#onhookstart)
- [`onHookEnd(beforeAll)`](#onhookend)
- [`onTestCaseReady`](#ontestcaseready)
- [`onTestAnnotate`](#ontestannotate) <Version>3.2.0</Version>
- [`onHookStart(beforeEach)`](#onhookstart)
- [`onHookEnd(beforeEach)`](#onhookend)
- [`onHookStart(afterEach)`](#onhookstart)
Expand Down Expand Up @@ -316,4 +317,21 @@ function onTestCaseResult(testCase: TestCase): Awaitable<void>

当测试完成运行或刚刚被跳过时调用此方法。请注意,如果有 `afterEach` 钩子,这将在 `afterEach` 钩子完成后调用。

<<<<<<< HEAD
此时,[`testCase.result()`](/advanced/api/test-case#result) 将具有非挂起状态。
=======
At this point, [`testCase.result()`](/advanced/api/test-case#result) will have non-pending state.

## onTestAnnotate <Version>3.2.0</Version> {#ontestannotate}

```ts
function onTestAnnotate(
testCase: TestCase,
annotation: TestAnnotation,
): Awaitable<void>
```

The `onTestAnnotate` hook is associated with the [`context.annotate`](/guide/test-context#annotate) method. When `annotate` is invoked, Vitest serialises it and sends the same attachment to the main thread where reporter can interact with it.

If the path is specified, Vitest stores it in a separate directory (configured by [`attachmentsDir`](/config/#attachmentsdir)) and modifies the `path` property to reference it.
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017
13 changes: 13 additions & 0 deletions advanced/api/test-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,18 @@ interface ModuleDiagnostic {
* This value is only available if the test was executed with `logHeapUsage` flag.
*/
readonly heap: number | undefined
/**
* The time spent importing every non-externalized dependency that Vitest has processed.
*/
readonly importDurations: Record<string, ImportDuration>
}

/** The time spent importing & executing a non-externalized file. */
interface ImportDuration {
/** The time spent importing & executing the file itself, not counting all non-externalized imports that the file does. */
selfTime: number

/** The time spent importing & executing the file and all its imports. */
totalTime: number
}
```
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.
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017
:::

## 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',
},
},
],
},
})
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017
```
:::

::: 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.
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017
:::

## 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.
>>>>>>> 5a7939506e3edd85f9c39e0bdfd9fbdf1c5ed017
:::

## onTestsRerun
Expand Down
Loading