You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,10 @@ Vitest is a next-generation testing framework powered by Vite. This is a monorep
35
35
-**Core directory test**: `CI=true pnpm test <test-file>` (for `test/core`)
36
36
-**Browser tests**: `CI=true pnpm test:browser:playwright` or `CI=true pnpm test:browser:webdriverio`
37
37
38
+
When writing tests, AVOID using `toContain` for validation. Prefer using `toMatchInlineSnapshot` to include the test error and its stack. If snapshot is failing, update the snapshot instead of reverting it to `toContain`.
39
+
40
+
If you need to typecheck tests, run `pnpm typecheck` from the root of the workspace.
41
+
38
42
### Testing Utilities
39
43
-**`runInlineTests`** from `test/test-utils/index.ts` - You must use this for complex file system setups (>1 file)
40
44
-**`runVitest`** from `test/test-utils/index.ts` - You can use this to run Vitest programmatically
Copy file name to clipboardExpand all lines: docs/api/test.md
+38-29Lines changed: 38 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -261,47 +261,42 @@ Whether the test is expected to fail. If it does, the test will pass, otherwise
261
261
262
262
-**Alias:**`it.extend`
263
263
264
-
Use`test.extend`toextendthetestcontextwithcustomfixtures. Thiswillreturnanew`test`andit's also extendable, so you can compose more fixtures or override existing ones by extending it as you need. See [Extend Test Context](/guide/test-context.html#test-extend) for more information.
264
+
Use`test.extend`toextendthetestcontextwithcustomfixtures. Thiswillreturnanew`test`andit's also extendable, so you can compose more fixtures or override existing ones by extending it as you need. See [Extend Test Context](/guide/test-context#extend-test-context) for more information.
265
265
266
266
```ts
267
267
import { test as baseTest, expect } from 'vitest'
268
268
269
-
const todos = []
270
-
const archive = []
271
-
272
-
const test = baseTest.extend({
273
-
todos: async ({ task }, use) => {
274
-
todos.push(1, 2, 3)
275
-
await use(todos)
276
-
todos.length = 0
277
-
},
278
-
archive,
279
-
})
280
-
281
-
test('add item', ({ todos }) => {
282
-
expect(todos.length).toBe(3)
269
+
export const test = baseTest
270
+
// Simple value - type is inferred as { port: number; host: string }
Use`test.scoped`tooverridefixturevaluesforalltestswithinthecurrentsuiteanditsnestedsuites. Thismustbecalledatthetoplevelofa`describe`block. See [ScopingValuestoSuite](/guide/test-context.html#scoping-values-to-suite) formoreinformation.
289
+
Use `test.override` to override fixture values for all tests within the current suite and its nested suites. This must be called at the top level of a `describe` block. See [Overriding Fixture Values](/guide/test-context.html#overriding-fixture-values) for more information.
for (const test oftestModule.children.allTests()) {
37
+
console.log(test.name, test.result().state)
38
+
}
44
39
}
45
40
}
46
41
```
@@ -60,9 +55,7 @@ export default defineConfig({
60
55
61
56
## Reported Tasks
62
57
63
-
Instead of using the tasks that reporters receive, it is recommended to use the Reported Tasks API instead.
64
-
65
-
You can get access to this API by calling `vitest.state.getReportedEntity(runnerTask)`:
58
+
Reported [events](/api/advanced/reporters) receive tasks for [tests](/api/advanced/test-case), [suites](/api/advanced/test-suite) and [modules](/api/advanced/test-module):
Copy file name to clipboardExpand all lines: docs/guide/common-errors.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,9 @@ title: Common Errors | Guide
8
8
9
9
If you receive an error that module cannot be found, it might mean several different things:
10
10
11
-
-1. You misspelled the path. Make sure the path is correct.
11
+
1. You misspelled the path. Make sure the path is correct.
12
12
13
-
-2. It's possible that you rely on `baseUrl` in your `tsconfig.json`. Vite doesn't take into account `tsconfig.json` by default, so you might need to install [`vite-tsconfig-paths`](https://www.npmjs.com/package/vite-tsconfig-paths) yourself, if you rely on this behaviour.
13
+
2. It's possible that you rely on `baseUrl` in your `tsconfig.json`. Vite doesn't take into account `tsconfig.json` by default, so you might need to install [`vite-tsconfig-paths`](https://www.npmjs.com/package/vite-tsconfig-paths) yourself, if you rely on this behavior.
14
14
15
15
```ts
16
16
import { defineConfig } from'vitest/config'
@@ -28,7 +28,7 @@ Or rewrite your path to not be relative to root:
28
28
+ import helpers from '../src/helpers'
29
29
```
30
30
31
-
-3. Make sure you don't have relative [aliases](/config/#alias). Vite treats them as relative to the file where the import is instead of the root.
31
+
3. Make sure you don't have relative [aliases](/config/#alias). Vite treats them as relative to the file where the import is instead of the root.
32
32
33
33
```ts
34
34
import { defineConfig } from'vitest/config'
@@ -47,7 +47,7 @@ export default defineConfig({
47
47
48
48
This error can happen when NodeJS's `fetch` is used with default [`pool: 'threads'`](/config/#threads). This issue is tracked on issue [Timeout abort can leave process(es) running in the background #3077](https://github.com/vitest-dev/vitest/issues/3077).
49
49
50
-
As work-around you can switch to [`pool: 'forks'`](/config/#forks) or [`pool: 'vmForks'`](/config/#vmforks).
50
+
As a workaround, you can switch to [`pool: 'forks'`](/config/#forks) or [`pool: 'vmForks'`](/config/#vmforks).
In these cases the native module is likely not built to be multi-thread safe. As work-around, you can switch to `pool: 'forks'` which runs the test cases in multiple `node:child_process` instead of multiple `node:worker_threads`.
123
+
In these cases the native module is likely not built to be multi-thread safe. As a workaround, you can switch to `pool: 'forks'` which runs the test cases in multiple `node:child_process` instead of multiple `node:worker_threads`.
Copy file name to clipboardExpand all lines: docs/guide/migration.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -442,7 +442,7 @@ export default defineConfig({
442
442
In Vitest 4.0 snapshots that include custom elements will print the shadow root contents. To restore the previous behavior, set the [`printShadowRoot` option](/config/#snapshotformat) to `false`.
443
443
444
444
```js{15-22}
445
-
// before Vite 4.0
445
+
// before Vitest 4.0
446
446
exports[`custom element with shadow root 1`] = `
447
447
"<body>
448
448
<div>
@@ -451,7 +451,7 @@ exports[`custom element with shadow root 1`] = `
0 commit comments