Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
641c1fb
chore: revert package.json config.ts eslint.config.ts
NoiseFan Dec 16, 2025
a1193e5
!docs: recovery /guide/why
NoiseFan Dec 16, 2025
7eac654
chore: update eslint rules
NoiseFan Dec 16, 2025
757c856
!docs: recovery /guide/
NoiseFan Dec 16, 2025
a010686
!docs: recovery /guide/features
NoiseFan Dec 16, 2025
4049ef6
!docs: recovery /guide/workspace
NoiseFan Dec 18, 2025
cf79017
!docs: recovery /guide/cli
NoiseFan Dec 18, 2025
68d3f01
!docs: recovery /guide/cli
NoiseFan Dec 23, 2025
379ea49
!docs: recovery /guide/filtering
NoiseFan Dec 23, 2025
a194f73
!docs: recovery /guide/reporters
NoiseFan Dec 23, 2025
9b03dc7
!docs: recovery /guide/coverage
NoiseFan Dec 23, 2025
a311748
!docs: recovery /guide/snapshot
NoiseFan Dec 23, 2025
23dadab
!docs: recovery /guide/mocking
NoiseFan Dec 23, 2025
47fef7b
!docs: recovery /guide/ui
NoiseFan Dec 25, 2025
250092e
!docs: recovery /guide/browser
NoiseFan Dec 25, 2025
ac15ae0
!docs: recovery /guide/testing-types
NoiseFan Dec 25, 2025
1af968e
!docs: recovery /guide/in-source
NoiseFan Dec 25, 2025
019f424
!docs: recovery /guide/in-source
NoiseFan Dec 25, 2025
01cd9be
!docs: recovery /guide/environment
NoiseFan Dec 25, 2025
e9be80a
!docs: recovery /guide/extending-matchers
NoiseFan Dec 25, 2025
435d4c5
!docs: recovery /guide/ide
NoiseFan Dec 25, 2025
1600454
!docs: recovery /guide/debugging
NoiseFan Dec 25, 2025
d0f9a90
!docs: recovery /guide/comparisons
NoiseFan Dec 25, 2025
d5223a6
!docs: recovery /guide/migration
NoiseFan Dec 25, 2025
221e75f
!docs: recovery /guide/common-errors
NoiseFan Dec 25, 2025
99885a3
!docs: recovery /guide/improving-performance
NoiseFan Dec 25, 2025
7b63004
!docs: recovery /api/
NoiseFan Dec 25, 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: 1 addition & 1 deletion .vitepress/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}

/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
Contributors: typeof import('./components/Contributors.vue')['default']
Expand Down
1 change: 0 additions & 1 deletion .vitepress/components/FeaturesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
>expect-type</a>
进行类型测试
</ListItem>
<ListItem>支持分片</ListItem>
</ul>
</template>

Expand Down
61 changes: 14 additions & 47 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export default () => {
en: {
label: 'English',
lang: 'en',
link: 'https://vitest.dev/',
link: 'https://v1.vitest.dev/',
},
},
head: [
['meta', { name: 'theme-color', content: '#729b1a' }],
['link', { rel: 'icon', href: '/favicon.ico', sizes: '48x48' }],
['link', { rel: 'icon', href: '/logo.svg', sizes: 'any', type: 'image/svg+xml' }],
['link', { rel: 'icon', href: '/favicon.ico', sizes: 'any' }],
['link', { rel: 'icon', href: '/logo.svg', type: 'image/svg+xml' }],
['meta', { name: 'author', content: `${teamMembers.map(c => c.name).join(', ')} and ${vitestName} contributors` }],
['meta', { name: 'keywords', content: 'vitest, vite, test, coverage, snapshot, react, vue, preact, svelte, solid, lit, marko, ruby, cypress, puppeteer, jsdom, happy-dom, test-runner, jest, typescript, esm, tinypool, tinyspy, node' }],
['meta', { property: 'og:title', content: vitestName }],
Expand Down Expand Up @@ -69,7 +69,7 @@ export default () => {
logo: '/logo.svg',

editLink: {
pattern: 'https://github.com/vitest-dev/docs-cn/tree/dev/:path',
pattern: 'https://github.com/vitest-dev/docs-cn/tree/v1/:path',
text: '为此页提供修改建议',
},

Expand Down Expand Up @@ -123,7 +123,7 @@ export default () => {
text: '社区指南',
link: contributing,
},
]
],
},
{
items: [
Expand All @@ -135,10 +135,6 @@ export default () => {
text: 'v0.x',
link: 'https://v0.vitest.dev/',
},
{
text: 'v1.x',
link: 'https://v1.vitest.dev/',
},
],
},
],
Expand Down Expand Up @@ -173,12 +169,12 @@ export default () => {
],
},
],
'/': [
'/guide/': [
{
text: '指南',
items: [
{
text: '简介',
text: '为什么是 Vitest?',
link: '/guide/why',
},
{
Expand Down Expand Up @@ -222,45 +218,12 @@ export default () => {
link: '/guide/testing-types',
},
{
text: 'Vitest UI',
text: 'UI 模式',
link: '/guide/ui',
},
{
text: '浏览器模式',
link: '/guide/browser/',
collapsed: false,
items: [
{
text: 'Assertion API',
link: '/guide/browser/assertion-api',
docFooterText: 'Assertion API | Browser Mode',
},
{
text: 'Retry-ability',
link: '/guide/browser/retry-ability',
docFooterText: 'Retry-ability | Browser Mode',
},
{
text: 'Context',
link: '/guide/browser/context',
docFooterText: 'Context | Browser Mode',
},
{
text: 'Interactivity API',
link: '/guide/browser/interactivity-api',
docFooterText: 'Interactivity API | Browser Mode',
},
{
text: 'Commands',
link: '/guide/browser/commands',
docFooterText: 'Commands | Browser Mode',
},
{
text: 'Examples',
link: '/guide/browser/examples',
docFooterText: 'Examples | Browser Mode',
},
],
link: '/guide/browser',
},
{
text: '源码内联测试',
Expand All @@ -287,7 +250,7 @@ export default () => {
link: '/guide/debugging',
},
{
text: '与其他测试框架对比',
text: '测试框架比较',
link: '/guide/comparisons',
},
{
Expand All @@ -304,6 +267,8 @@ export default () => {
},
],
},
],
'/api/': [
{
text: 'API',
items: [
Expand Down Expand Up @@ -337,6 +302,8 @@ export default () => {
},
],
},
],
'/config/': [
{
text: '配置',
items: [
Expand Down
1 change: 0 additions & 1 deletion advanced/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ Vitest 实例需要当前的测试模式。它可以是以下之一:

你可以使用 `start` 方法运行测试或者基准测试。你还可以传递一个字符串数组以筛选测试文件。


### `provide`

Vitest 暴露了`provide`方法,它是`vitest.getCoreWorkspaceProject().provide`的简写。使用该方法,您可以从主线程向测试传递值。所有值在存储前都会通过 `structuredClone`进行检查,但值本身不会被克隆。
Expand Down
6 changes: 3 additions & 3 deletions advanced/runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface VitestRunner {
* 这是在实际运行测试函数之前被调用的。
* 此时已经有了带有 "state" 和 "startTime" 属性的 "result" 对象。
*/
onBeforeTryTask?: (test: TaskPopulated, options: { retry: number, repeats: number }) => unknown
onBeforeTryTask?: (test: TaskPopulated, options: { retry: number; repeats: number }) => unknown
/**
* 这是在结果和状态都被设置之后被调用的。
*/
Expand All @@ -40,7 +40,7 @@ export interface VitestRunner {
* 这是在运行测试函数后立即被调用的。此时还没有新的状态。
* 如果测试函数抛出异常,将不会调用此方法。
*/
onAfterTryTask?: (test: TaskPopulated, options: { retry: number, repeats: number }) => unknown
onAfterTryTask?: (test: TaskPopulated, options: { retry: number; repeats: number }) => unknown

/**
* 这是在运行单个测试套件之前被调用的,此时还没有测试结果。
Expand Down Expand Up @@ -80,7 +80,7 @@ export interface VitestRunner {
/**
* 这个方法被用于 "test" 和 "custom" 处理程序。
* 你可以在 "setupFiles" 中使用 "beforeAll" 来定义自定义上下文,而不是使用 runner。
* 更多信息请参考:https://vitest.dev/advanced/runner.html#your-task-function
* 更多信息请参考:https://v1.vitest.dev/advanced/runner.html#your-task-function
*/
extendTaskContext?: <T extends Test | Custom>(context: TaskContext<T>) => TaskContext<T>
/**
Expand Down
21 changes: 10 additions & 11 deletions api/expect-typeof.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ expectTypeOf<string | number>().not.toMatchTypeOf<number>()
```ts twoslash
import { expectTypeOf } from 'vitest'

type ResponsiveProp<T> = T | T[] | { xs?: T, sm?: T, md?: T }
type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }

interface CSSProperties {
margin?: string
Expand All @@ -66,10 +66,10 @@ const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
expectTypeOf(getResponsiveProp(cssProperties))
.extract<{ xs?: any }>() // extracts the last type from a union
.toEqualTypeOf<{
xs?: CSSProperties
sm?: CSSProperties
md?: CSSProperties
}>()
xs?: CSSProperties
sm?: CSSProperties
md?: CSSProperties
}>()

expectTypeOf(getResponsiveProp(cssProperties))
.extract<unknown[]>() // extracts an array from a union
Expand All @@ -93,17 +93,16 @@ type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }

interface CSSProperties { margin?: string; padding?: string }

function getResponsiveProp<T>(\_props: T): ResponsiveProp<T> {
return {}
function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
return {}
}

const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }

expectTypeOf(getResponsiveProp(cssProperties))
.exclude<unknown[]>()
.exclude<{ xs?: unknown }>() // or just .exclude<unknown[] | { xs?: unknown }>()
.toEqualTypeOf<CSSProperties>()

.exclude<unknown[]>()
.exclude<{ xs?: unknown }>() // or just .exclude<unknown[] | { xs?: unknown }>()
.toEqualTypeOf<CSSProperties>()
```

::: warning
Expand Down
11 changes: 3 additions & 8 deletions api/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ expect(input).toBe(2) // jest API
此外,`expect` 可以静态地使用来访问匹配器函数,稍后将会介绍。

::: warning
如果表达式没有类型错误,则 `expect` 对测试类型没有影响。 如果你想使用 Vitest 作为[类型检查器](/guide/testing-types),请使用 [`expectTypeOf`](/api/expect-typeof) 或 [`assertType`](/api/assert-type) 。
如果表达式没有类型错误,则 `expect` 对测试类型没有影响。 如果你想使用 Vitest 作为 [类型检查器](/guide/testing-types) ,请使用 [`expectTypeOf`](/api/expect-typeof) 或 [`assertType`](/api/assert-type) 。
:::

## soft
Expand Down Expand Up @@ -1020,20 +1020,19 @@ test('spy function returns bananas on second call', () => {

- **类型**: `() => Awaitable<void>`


此断言检查函数是否至少成功解析过一次值(即未reject)。需要将 spy 函数传递给 `expect`。

如果函数返回了一个promise,但尚未resolved,则将会失败。

```ts twoslash
// @filename: db/apples.js
/** @type {any} */
const db = {}
export default db
// @filename: test.ts
// ---cut---
import { expect, test, vi } from 'vitest'
import db from './db/apples.js'
const db = {}
export default db

async function getApplesPrice(amount: number) {
return amount * await db.get('price')
Expand All @@ -1057,7 +1056,6 @@ test('spy function resolved a value', async () => {

这只会计算已resolved的promises。如果函数返回了一个promise,但尚未resolved,则不会计算在内。


```ts twoslash
import { expect, test, vi } from 'vitest'

Expand All @@ -1075,13 +1073,10 @@ test('spy function resolved a value two times', async () => {

- **类型**: `(returnValue: any) => Awaitable<void>`



您可以调用此断言来检查函数是否至少成功解析过一次某个值。需要将 spy 函数传递给`expect`。

如果函数返回了一个promise,但尚未resolved,则将会失败。


```ts twoslash
import { expect, test, vi } from 'vitest'

Expand Down
Loading