Skip to content

Commit ce6c13b

Browse files
committed
Merge branch 'main' of github.com:vitest-dev/vitest into feat/provide-signal
2 parents ace7edd + 69ac92c commit ce6c13b

File tree

82 files changed

+2421
-1328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2421
-1328
lines changed

docs/advanced/runner.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ interface Test<ExtraContext = object> extends TaskBase {
209209
*/
210210
file: File
211211
/**
212-
* Whether the task was skipped by calling `t.skip()`.
212+
* Whether the task was skipped by calling `context.skip()`.
213213
*/
214214
pending?: boolean
215215
/**

docs/api/index.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ test('skipped test', (context) => {
167167
})
168168
```
169169

170-
Since Vitest 3.1, if the condition is unknonwn, you can provide it to the `skip` method as the first arguments:
170+
Since Vitest 3.1, if the condition is unknown, you can provide it to the `skip` method as the first arguments:
171171

172172
```ts
173173
import { assert, test } from 'vitest'
@@ -1279,16 +1279,6 @@ test('performs an organization query', async () => {
12791279

12801280
::: tip
12811281
This hook is always called in reverse order and is not affected by [`sequence.hooks`](/config/#sequence-hooks) option.
1282-
1283-
<!-- TODO: should it be called? https://github.com/vitest-dev/vitest/pull/7069 -->
1284-
Note that this hook is not called if test was skipped with a dynamic `ctx.skip()` call:
1285-
1286-
```ts{2}
1287-
test('skipped dynamically', (t) => {
1288-
onTestFinished(() => {}) // not called
1289-
t.skip()
1290-
})
1291-
```
12921282
:::
12931283

12941284
### onTestFailed

docs/guide/browser/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Command is a function that invokes another function on the server and passes dow
1111

1212
### Files Handling
1313

14-
You can use `readFile`, `writeFile` and `removeFile` API to handle files inside your browser tests. All paths are resolved relative to the test file even if they are called in a helper function located in another file.
14+
You can use the `readFile`, `writeFile`, and `removeFile` APIs to handle files in your browser tests. Since Vitest 3.2, all paths are resolved relative to the [project](/guide/workspace) root (which is `process.cwd()`, unless overriden manually). Previously, paths were resolved relative to the test file.
1515

1616
By default, Vitest uses `utf-8` encoding but you can override it with options.
1717

docs/guide/cli-generated.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,13 @@ Omit annotation lines from the output (default: `false`)
761761

762762
Print basic prototype Object and Array (default: `true`)
763763

764+
### diff.maxDepth
765+
766+
- **CLI:** `--diff.maxDepth <maxDepth>`
767+
- **Config:** [diff.maxDepth](/config/#diff-maxdepth)
768+
769+
Limit the depth to recurse when printing nested objects (default: `20`)
770+
764771
### diff.truncateThreshold
765772

766773
- **CLI:** `--diff.truncateThreshold <threshold>`

docs/guide/test-context.md

Lines changed: 80 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ it('should work', ({ task }) => {
2222

2323
## Built-in Test Context
2424

25-
#### `context.task`
25+
#### `task`
2626

2727
A readonly object containing metadata about the test.
2828

29-
#### `context.expect`
29+
#### `expect`
3030

3131
The `expect` API bound to the current test:
3232

@@ -52,7 +52,12 @@ it.concurrent('math is hard', ({ expect }) => {
5252
})
5353
```
5454

55-
#### `context.skip`
55+
#### `skip`
56+
57+
```ts
58+
function skip(note?: string): never
59+
function skip(condition: boolean, note?: string): void
60+
```
5661

5762
Skips subsequent test execution and marks test as skipped:
5863

@@ -65,6 +70,15 @@ it('math is hard', ({ skip }) => {
6570
})
6671
```
6772

73+
Since Vitest 3.1, it accepts a boolean parameter to skip the test conditionally:
74+
75+
```ts
76+
it('math is hard', ({ skip, mind }) => {
77+
skip(mind === 'foggy')
78+
expect(2 + 2).toBe(5)
79+
})
80+
```
81+
6882
#### `context.signal` <Version>3.2.0</Version> {#context-signal}
6983

7084
An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that can be aborted by Vitest. The signal is aborted in these situations:
@@ -80,6 +94,14 @@ it('stop request when test times out', async ({ signal }) => {
8094
}, 2000)
8195
```
8296

97+
#### `onTestFailed`
98+
99+
The [`onTestFailed`](/api/#ontestfailed) hook bound to the current test. This API is useful if you are running tests concurrently and need to have a special handling only for this specific test.
100+
101+
#### `onTestFinished`
102+
103+
The [`onTestFinished`](/api/#ontestfailed) hook bound to the current test. This API is useful if you are running tests concurrently and need to have a special handling only for this specific test.
104+
83105
## Extend Test Context
84106

85107
Vitest provides two different ways to help you extend the test context.
@@ -88,15 +110,15 @@ Vitest provides two different ways to help you extend the test context.
88110

89111
Like [Playwright](https://playwright.dev/docs/api/class-test#test-extend), you can use this method to define your own `test` API with custom fixtures and reuse it anywhere.
90112

91-
For example, we first create `myTest` with two fixtures, `todos` and `archive`.
113+
For example, we first create the `test` collector with two fixtures: `todos` and `archive`.
92114

93115
```ts [my-test.ts]
94-
import { test } from 'vitest'
116+
import { test as baseTest } from 'vitest'
95117
96118
const todos = []
97119
const archive = []
98120
99-
export const myTest = test.extend({
121+
export const test = baseTest.extend({
100122
todos: async ({}, use) => {
101123
// setup the fixture before each test function
102124
todos.push(1, 2, 3)
@@ -115,16 +137,16 @@ Then we can import and use it.
115137

116138
```ts [my-test.test.ts]
117139
import { expect } from 'vitest'
118-
import { myTest } from './my-test.js'
140+
import { test } from './my-test.js'
119141
120-
myTest('add items to todos', ({ todos }) => {
142+
test('add items to todos', ({ todos }) => {
121143
expect(todos.length).toBe(3)
122144
123145
todos.push(4)
124146
expect(todos.length).toBe(4)
125147
})
126148
127-
myTest('move items from todos to archive', ({ todos, archive }) => {
149+
test('move items from todos to archive', ({ todos, archive }) => {
128150
expect(todos.length).toBe(3)
129151
expect(archive.length).toBe(0)
130152
@@ -134,10 +156,12 @@ myTest('move items from todos to archive', ({ todos, archive }) => {
134156
})
135157
```
136158

137-
We can also add more fixtures or override existing fixtures by extending `myTest`.
159+
We can also add more fixtures or override existing fixtures by extending our `test`.
138160

139161
```ts
140-
export const myTest2 = myTest.extend({
162+
import { test as todosTest } from './my-test.js'
163+
164+
export const test = todosTest.extend({
141165
settings: {
142166
// ...
143167
}
@@ -149,34 +173,35 @@ export const myTest2 = myTest.extend({
149173
Vitest runner will smartly initialize your fixtures and inject them into the test context based on usage.
150174

151175
```ts
152-
import { test } from 'vitest'
176+
import { test as baseTest } from 'vitest'
153177
154-
async function todosFn({ task }, use) {
155-
await use([1, 2, 3])
156-
}
157-
158-
const myTest = test.extend({
159-
todos: todosFn,
178+
const test = baseTest.extend<{
179+
todos: number[]
180+
archive: number[]
181+
}>({
182+
todos: async ({ task }, use) => {
183+
await use([1, 2, 3])
184+
},
160185
archive: []
161186
})
162187
163-
// todosFn will not run
164-
myTest('', () => {})
165-
myTest('', ({ archive }) => {})
188+
// todos will not run
189+
test('skip', () => {})
190+
test('skip', ({ archive }) => {})
166191
167-
// todosFn will run
168-
myTest('', ({ todos }) => {})
192+
// todos will run
193+
test('run', ({ todos }) => {})
169194
```
170195

171196
::: warning
172197
When using `test.extend()` with fixtures, you should always use the object destructuring pattern `{ todos }` to access context both in fixture function and test function.
173198

174199
```ts
175-
myTest('context must be destructured', (context) => { // [!code --]
200+
test('context must be destructured', (context) => { // [!code --]
176201
expect(context.todos.length).toBe(2)
177202
})
178203

179-
myTest('context must be destructured', ({ todos }) => { // [!code ++]
204+
test('context must be destructured', ({ todos }) => { // [!code ++]
180205
expect(todos.length).toBe(2)
181206
})
182207
```
@@ -331,19 +356,46 @@ interface MyFixtures {
331356
archive: number[]
332357
}
333358

334-
const myTest = test.extend<MyFixtures>({
359+
const test = baseTest.extend<MyFixtures>({
335360
todos: [],
336361
archive: []
337362
})
338363

339-
myTest('types are defined correctly', ({ todos, archive }) => {
364+
test('types are defined correctly', ({ todos, archive }) => {
340365
expectTypeOf(todos).toEqualTypeOf<number[]>()
341366
expectTypeOf(archive).toEqualTypeOf<number[]>()
342367
})
343368
```
344369
370+
::: info Type Infering
371+
Note that Vitest doesn't support infering the types when the `use` function is called. It is always preferable to pass down the whole context type as the generic type when `test.extend` is called:
372+
373+
```ts
374+
import { test as baseTest } from 'vitest'
375+
376+
const test = baseTest.extend<{
377+
todos: number[]
378+
schema: string
379+
}>({
380+
todos: ({ schema }, use) => use([]),
381+
schema: 'test'
382+
})
383+
384+
test('types are correct', ({
385+
todos, // number[]
386+
schema, // string
387+
}) => {
388+
// ...
389+
})
390+
```
391+
:::
392+
345393
### `beforeEach` and `afterEach`
346394
395+
::: danger Deprecated
396+
This is an outdated way of extending context and it will not work when the `test` is extended with `test.extend`.
397+
:::
398+
347399
The contexts are different for each test. You can access and extend them within the `beforeEach` and `afterEach` hooks.
348400
349401
```ts
@@ -361,7 +413,7 @@ it('should work', ({ foo }) => {
361413
362414
#### TypeScript
363415
364-
To provide property types for all your custom contexts, you can aggregate the `TestContext` type by adding
416+
To provide property types for all your custom contexts, you can augment the `TestContext` type by adding
365417
366418
```ts
367419
declare module 'vitest' {

docs/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"devDependencies": {
2121
"@iconify-json/carbon": "catalog:",
2222
"@iconify-json/logos": "catalog:",
23-
"@shikijs/transformers": "^3.2.2",
24-
"@shikijs/vitepress-twoslash": "^3.2.2",
23+
"@shikijs/transformers": "^3.3.0",
24+
"@shikijs/vitepress-twoslash": "^3.3.0",
2525
"@unocss/reset": "catalog:",
2626
"@vite-pwa/assets-generator": "^0.2.6",
2727
"@vite-pwa/vitepress": "^0.5.4",
@@ -32,7 +32,7 @@
3232
"unplugin-vue-components": "catalog:",
3333
"vite": "^5.2.8",
3434
"vite-plugin-pwa": "^0.21.2",
35-
"vitepress": "2.0.0-alpha.4",
35+
"vitepress": "2.0.0-alpha.5",
3636
"vitepress-plugin-group-icons": "^1.5.2",
3737
"vitepress-plugin-tabs": "^0.7.0",
3838
"workbox-window": "^7.3.0"

examples/lit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"devDependencies": {
2020
"@vitest/browser": "latest",
2121
"jsdom": "latest",
22-
"playwright": "^1.51.1",
22+
"playwright": "^1.52.0",
2323
"vite": "latest",
2424
"vitest": "latest"
2525
},

examples/workspace/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@testing-library/react": "^13.4.0",
1414
"@testing-library/user-event": "^14.6.1",
1515
"@types/react": "^19.1.2",
16-
"@vitejs/plugin-react": "^4.3.4",
16+
"@vitejs/plugin-react": "^4.4.1",
1717
"@vitest/ui": "latest",
1818
"fastify": "^4.29.0",
1919
"jsdom": "^24.1.3",

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "@vitest/monorepo",
33
"type": "module",
4-
"version": "3.1.2",
4+
"version": "3.1.3",
55
"private": true,
6-
"packageManager": "pnpm@10.8.1",
6+
"packageManager": "pnpm@10.9.0",
77
"description": "Next generation testing framework powered by Vite",
88
"engines": {
99
"node": "^18.0.0 || >=20.0.0"
@@ -38,7 +38,7 @@
3838
"devDependencies": {
3939
"@antfu/eslint-config": "^4.12.0",
4040
"@antfu/ni": "^24.3.0",
41-
"@playwright/test": "^1.51.1",
41+
"@playwright/test": "^1.52.0",
4242
"@rollup/plugin-commonjs": "^28.0.3",
4343
"@rollup/plugin-json": "^6.1.0",
4444
"@rollup/plugin-node-resolve": "^16.0.1",
@@ -50,8 +50,8 @@
5050
"@vitest/ui": "workspace:*",
5151
"bumpp": "^10.1.0",
5252
"changelogithub": "^13.13.0",
53-
"esbuild": "^0.25.2",
54-
"eslint": "^9.24.0",
53+
"esbuild": "^0.25.3",
54+
"eslint": "^9.26.0",
5555
"magic-string": "^0.30.17",
5656
"pathe": "^2.0.3",
5757
"rimraf": "^6.0.1",
@@ -61,11 +61,11 @@
6161
"tinyglobby": "catalog:",
6262
"tsx": "^4.19.3",
6363
"typescript": "^5.8.3",
64-
"unplugin-isolated-decl": "^0.13.6",
65-
"unplugin-oxc": "^0.3.3",
64+
"unplugin-isolated-decl": "^0.13.9",
65+
"unplugin-oxc": "^0.3.5",
6666
"vite": "^6.2.0",
6767
"vitest": "workspace:*",
68-
"zx": "^8.5.2"
68+
"zx": "^8.5.3"
6969
},
7070
"pnpm": {
7171
"overrides": {

packages/browser/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vitest/browser",
33
"type": "module",
4-
"version": "3.1.2",
4+
"version": "3.1.3",
55
"description": "Browser running for Vitest",
66
"license": "MIT",
77
"funding": "https://opencollective.com/vitest",
@@ -103,17 +103,17 @@
103103
"@vitest/ui": "workspace:*",
104104
"@vitest/ws-client": "workspace:*",
105105
"@wdio/protocols": "^9.12.5",
106-
"@wdio/types": "^9.12.3",
106+
"@wdio/types": "^9.12.6",
107107
"birpc": "catalog:",
108108
"flatted": "catalog:",
109109
"ivya": "^1.6.0",
110110
"mime": "^4.0.7",
111111
"pathe": "catalog:",
112112
"periscopic": "^4.0.2",
113-
"playwright": "^1.51.1",
114-
"playwright-core": "^1.51.1",
113+
"playwright": "^1.52.0",
114+
"playwright-core": "^1.52.0",
115115
"safaridriver": "^1.0.0",
116116
"vitest": "workspace:*",
117-
"webdriverio": "^9.12.5"
117+
"webdriverio": "^9.12.7"
118118
}
119119
}

0 commit comments

Comments
 (0)