Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 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
8931929
docs(en): merging all conflicts
docschina-bot Jun 3, 2025
5e6b2d2
docs: package and config menu
elonehoo Jun 4, 2025
46c8341
docs: content - 1
elonehoo Jun 4, 2025
d26b1fe
docs: content - 2
elonehoo Jun 4, 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>
105 changes: 23 additions & 82 deletions .vitepress/components/FeaturesList.vue
Original file line number Diff line number Diff line change
@@ -1,87 +1,28 @@
<template>
<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>
通用的配置、转换器、解析器和插件。
</ListItem>
<ListItem>使用与你的应用相同的设置来运行测试!</ListItem>
<ListItem>智能文件监听模式,就像是测试的 HMR!</ListItem>
<ListItem>支持对 Vue、React、Svelte、Lit等框架进行组件测试。</ListItem>
<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> 的配置、转换器、解析器和插件</ListItem>
<ListItem>使用与应用程序相同的设置来运行测试!</ListItem>
<ListItem>智能即时监听模式,如同测试的热模块替换!</ListItem>
<ListItem>支持 Vue、React、Svelte、Lit、Marko 等组件测试</ListItem>
<ListItem>开箱即用的 TypeScript / JSX 支持</ListItem>
<ListItem>ESM 优先,支持模块顶级 await</ListItem>
<ListItem>
通过
<a
target="_blank"
href="https://github.com/tinylibs/tinypool"
rel="noopener noreferrer"
>Tinypool</a>
使用 Worker 线程尽可能多地并发运行
</ListItem>
<ListItem>
使用
<a
target="_blank"
href="https://github.com/tinylibs/tinybench"
rel="noopener noreferrer"
>Tinybench</a>
来支持基准测试
</ListItem>
<ListItem>套件和测试的过滤、超时、并发配置</ListItem>
<ListItem>支持 <a href="/guide/workspace">Workspace</a></ListItem>
<ListItem>
<a href="/guide/snapshot"> Jest 的快照功能 </a>
</ListItem>
<ListItem>
内置
<a target="_blank" href="https://www.chaijs.com/" rel="nofollow">Chai</a>
进行断言 + 与
<a href="https://jestjs.io/zh-Hans/docs/expect" rel="nofollow">Jest expect 语法</a>兼容的 API
</ListItem>
<ListItem>
内置用于对象模拟(Mock)的
<a
target="_blank"
href="https://github.com/Aslemammad/tinyspy"
rel="nofollow"
>Tinyspy</a>
</ListItem>
<ListItem>
使用
<a target="_blank" href="https://github.com/jsdom/jsdom">jsdom</a> 或
<a target="_blank" href="https://github.com/capricorn86/happy-dom">happy-dom</a>
用于 DOM 模拟
</ListItem>
<ListItem><a href="https://vitest.dev/guide/browser/" rel="noopener noreferrer">浏览器模式</a> 用于在浏览器中运行组件测试</ListItem>
<ListItem>
通过
<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 语言的
<a target="_blank" href="https://cn.vitest.dev/guide/in-source.html">源码内联测试</a>
</ListItem>
<ListItem>
通过
<a
target="_blank"
href="https://github.com/mmkal/expect-type"
rel="noopener noreferrer"
>expect-type</a>
进行类型测试
</ListItem>
<ListItem>支持分片</ListItem>
<ListItem>ESM 优先,支持顶级 await</ListItem>
<ListItem>通过 <a target="_blank" href="https://github.com/tinylibs/tinypool" rel="noopener noreferrer">Tinypool</a> 实现 Worker 多线程</ListItem>
<ListItem>使用 <a target="_blank" href="https://github.com/tinylibs/tinybench" rel="noopener noreferrer">Tinybench</a> 进行基准测试</ListItem>
<ListItem>支持测试套件和测试的过滤、超时、并发</ListItem>
<ListItem>支持<a href="/guide/projects">多项目</a></ListItem>
<ListItem>内置 <a target="_blank" href="https://www.chaijs.com/" rel="noopener noreferrer">Chai</a> 断言库 + 兼容 <a target="_blank" href="https://jestjs.io/docs/expect" rel="noopener noreferrer">Jest expect</a> API</ListItem>
<ListItem>内置 <a target="_blank" href="https://github.com/tinylibs/tinyspy" rel="noopener noreferrer">Tinyspy</a> 用于模拟</ListItem>
<ListItem>使用 <a target="_blank" href="https://github.com/capricorn86/happy-dom" rel="noopener noreferrer">happy-dom</a> 或 <a target="_blank" href="https://github.com/jsdom/jsdom" rel="noopener noreferrer">jsdom</a> 进行 DOM 模拟</ListItem>
<ListItem><a href="https://vitest.dev/guide/browser/" rel="noopener noreferrer">浏览器模式</a>用于在浏览器中运行组件测试</ListItem>
<ListItem>通过 <a target="_blank" href="https://v8.dev/blog/javascript-code-coverage" rel="noopener noreferrer">v8</a> 或 <a target="_blank" href="https://istanbul.js.org/" rel="noopener noreferrer">istanbul</a> 进行代码覆盖率检测</ListItem>
<ListItem>类似 Rust 的<a href="/guide/in-source">源码内测试</a></ListItem>
<ListItem>通过 <a target="_blank" href="https://github.com/mmkal/expect-type" rel="noopener noreferrer">expect-type</a> 进行类型测试</ListItem>
<ListItem>分片支持</ListItem>
<ListItem>未捕获错误报告</ListItem>
</ul>
</template>

Expand Down
12 changes: 10 additions & 2 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ function guide(): DefaultTheme.SidebarItem[] {
link: '/guide/filtering',
},
{
text: '工作空间',
link: '/guide/workspace',
text: '测试项目',
link: '/guide/projects',
},
{
text: '报告器「Reporters」',
Expand All @@ -488,6 +488,10 @@ function guide(): DefaultTheme.SidebarItem[] {
text: '模拟对象',
link: '/guide/mocking',
},
{
text: 'Parallelism',
link: '/guide/parallelism',
},
{
text: '类型测试',
link: '/guide/testing-types',
Expand All @@ -504,6 +508,10 @@ function guide(): DefaultTheme.SidebarItem[] {
text: '测试上下文',
link: '/guide/test-context',
},
{
text: '测试注释',
link: '/guide/test-annotations',
},
{
text: '测试环境',
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
2 changes: 1 addition & 1 deletion advanced/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const { vitestConfig, viteConfig } = await resolveConfig({
:::

::: warning
`resolveConfig` 不会解析 `workspace`。要解析工作区配置,Vitest 需要一个已建立的 Vite 服务器。
`resolveConfig` 不能解析 `projects` 。为了解决项目配置, Vitest 需要一个已建立的 Vite 服务器。

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

与 [`reporter.onInit`](/advanced/api/reporters#oninit) 不同,此 hooks 在 Vitest 生命周期的早期运行,允许我们更改 `coverage``reporters` 等配置。更值得注意的变化是,如果我们的插件是在项目中定义而不是在全局配置中定义的,我们可以从 [工作区项目](/guide/workspace) 操作全局配置
与 [`reporter.onInit`](/advanced/api/ reporter#oninit) 不同,这个 hook 在 Vitest 生命周期的早期运行,允许我们对`coverage``reporters`等配置进行更改。一个更值得注意的变化是,如果我们的插件是在项目中定义的而不是在全局配置中,我们可以从 [test project](/guide/projects) 中操作全局配置

## Context

Expand Down Expand Up @@ -93,10 +93,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 +107,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:
>>>>>>> 66a9b6b6b1842fb5487d24c3e913f0ebfd55103b

```ts
vitest.config.project.push('my-project-name')
Expand All @@ -117,7 +121,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.
>>>>>>> 66a9b6b6b1842fb5487d24c3e913f0ebfd55103b

项目的 `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.
>>>>>>> 66a9b6b6b1842fb5487d24c3e913f0ebfd55103b
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
}
```
Loading