Skip to content

Commit 045179e

Browse files
committed
Merge branch 'main' of github.com:vitest-dev/vitest into 12-08-feat_experimental_allow_disabling_the_module_runner
2 parents 41d181e + f865d2b commit 045179e

File tree

88 files changed

+1511
-315
lines changed

Some content is hidden

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

88 files changed

+1511
-315
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<picture>
66
<source media="(prefers-color-scheme: dark)" srcset="https://vitest.dev/vitest-light.svg">
77
<source media="(prefers-color-scheme: light)" srcset="https://vitest.dev/vitest-dark.svg">
8-
<img alt="rolldown logo" src="https://vitest.dev/vitest-dark.svg" height="60">
8+
<img alt="Vitest logo" src="https://vitest.dev/vitest-dark.svg" height="60">
99
</picture>
1010
</a>
1111
<br>

docs/.vitepress/config.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
66
import {
77
groupIconMdPlugin,
88
groupIconVitePlugin,
9-
localIconLoader,
109
} from 'vitepress-plugin-group-icons'
1110
import llmstxt from 'vitepress-plugin-llms'
1211
import { version } from '../../package.json'
@@ -50,6 +49,7 @@ export default ({ mode }: { mode: string }) => {
5049
},
5150
head: [
5251
['meta', { name: 'theme-color', content: '#22FF84' }],
52+
['link', { rel: 'icon', href: '/favicon.ico', sizes: '48x48' }],
5353
['link', { rel: 'icon', href: '/logo-without-border.svg', type: 'image/svg+xml' }],
5454
['meta', { name: 'author', content: `${teamMembers.map(c => c.name).join(', ')} and ${vitestName} contributors` }],
5555
['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, tinyspy, node' }],
@@ -63,24 +63,27 @@ export default ({ mode }: { mode: string }) => {
6363
['link', { rel: 'me', href: 'https://m.webtoo.ls/@vitest' }],
6464
['link', { rel: 'mask-icon', href: '/logo.svg', color: '#ffffff' }],
6565
['link', { rel: 'apple-touch-icon', href: '/apple-touch-icon.png', sizes: '180x180' }],
66+
[
67+
'script',
68+
{
69+
'src': 'https://cdn.usefathom.com/script.js',
70+
'data-site': 'BEAFAKYG',
71+
'data-spa': 'auto',
72+
'defer': '',
73+
},
74+
],
6675
],
6776
lastUpdated: true,
6877
vite: {
6978
plugins: [
7079
groupIconVitePlugin({
7180
customIcon: {
7281
'CLI': 'vscode-icons:file-type-shell',
73-
'vitest.shims': localIconLoader(import.meta.url, '../public/logo-without-border.svg'),
74-
'vitest.config': localIconLoader(import.meta.url, '../public/logo-without-border.svg'),
75-
'vitest.workspace': localIconLoader(import.meta.url, '../public/logo-without-border.svg'),
7682
'.spec.ts': 'vscode-icons:file-type-testts',
7783
'.test.ts': 'vscode-icons:file-type-testts',
7884
'.spec.js': 'vscode-icons:file-type-testjs',
7985
'.test.js': 'vscode-icons:file-type-testjs',
80-
'marko': 'vscode-icons:file-type-marko',
81-
'qwik': 'logos:qwik-icon',
8286
'next': '',
83-
'vite.config': localIconLoader(import.meta.url, '../public/logo-without-border-vite.svg'),
8487
},
8588
}),
8689
llmstxt(),

docs/.vitepress/scripts/pwa.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const pwa: PwaOptions = {
5252
screenshots: [{
5353
src: 'og.jpg',
5454
sizes: '2258x1185',
55-
type: 'image/png',
55+
type: 'image/jpeg',
5656
label: `Screenshot of ${vitestName}`,
5757
}],
5858
handle_links: 'preferred',

docs/.vitepress/scripts/transformHead.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ export async function transformHead({ pageData }: TransformContext): Promise<Hea
1313
})
1414

1515
head.push(['link', { rel: 'prefetch', href: '/logo.svg', as: 'image' }])
16-
if (home) {
17-
head.push(['link', { rel: 'prefetch', href: '/logo-shadow.svg', as: 'image' }])
18-
head.push(['link', { rel: 'prefetch', href: '/sponsors/antfu.svg', as: 'image' }])
19-
head.push(['link', { rel: 'prefetch', href: '/sponsors/sheremet-va.svg', as: 'image' }])
20-
head.push(['link', { rel: 'prefetch', href: '/sponsors/patak-dev.svg', as: 'image' }])
21-
head.push(['link', { rel: 'prefetch', href: '/netlify.svg', as: 'image' }])
22-
}
2316

2417
return head
2518
}

docs/api/advanced/reporters.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ export default new MyReporter()
118118
```
119119
:::
120120

121-
::: tip DEPRECATION NOTICE
122-
This method was added in Vitest 3, replacing `onPathsCollected` and `onSpecsCollected`, both of which are now deprecated.
123-
:::
124-
125121
## onTestRunEnd
126122

127123
```ts
@@ -185,10 +181,6 @@ export default new MyReporter()
185181
```
186182
:::
187183

188-
::: tip DEPRECATION NOTICE
189-
This method was added in Vitest 3, replacing `onFinished`, which is now deprecated.
190-
:::
191-
192184
## onCoverage
193185

194186
```ts

docs/api/advanced/test-case.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,11 @@ function artifacts(): ReadonlyArray<TestArtifact>
280280
```
281281

282282
[Test artifacts](/api/advanced/artifacts) recorded via the `recordArtifact` API during the test execution.
283+
284+
## toTestSpecification <Version>4.1.0</Version> {#totestspecification}
285+
286+
```ts
287+
function toTestSpecification(): TestSpecification
288+
```
289+
290+
Returns a new [test specification](/api/advanced/test-specification) that can be used to filter or run this specific test case.

docs/api/advanced/test-module.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,11 @@ interface ImportDuration {
124124
## viteEnvironment <Version type="experimental">4.0.15</Version> <Experimental /> {#viteenvironment}
125125
126126
This is a Vite's [`DevEnvironment`](https://vite.dev/guide/api-environment) that transforms all files inside of the test module.
127+
128+
## toTestSpecification <Version>4.1.0</Version> {#totestspecification}
129+
130+
```ts
131+
function toTestSpecification(): TestSpecification
132+
```
133+
134+
Returns a new [test specification](/api/advanced/test-specification) that can be used to filter or run this specific test module.

docs/api/advanced/test-suite.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,11 @@ describe('the validation works correctly', () => {
218218
:::tip
219219
If metadata was attached during collection (outside of the `test` function), then it will be available in [`onTestModuleCollected`](./reporters#ontestmodulecollected) hook in the custom reporter.
220220
:::
221+
222+
## toTestSpecification <Version>4.1.0</Version> {#totestspecification}
223+
224+
```ts
225+
function toTestSpecification(): TestSpecification
226+
```
227+
228+
Returns a new [test specification](/api/advanced/test-specification) that can be used to filter or run this specific test suite.

docs/api/browser/context.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,71 @@ export const utils: {
231231
getElementError(selector: string, container?: Element): Error
232232
}
233233
```
234+
235+
### configurePrettyDOM <Version>4.0.0</Version> {#configureprettydom}
236+
237+
The `configurePrettyDOM` function allows you to configure default options for the `prettyDOM` and `debug` functions. This is useful for customizing how HTML is formatted in test failure messages.
238+
239+
```ts
240+
import { utils } from 'vitest/browser'
241+
242+
utils.configurePrettyDOM({
243+
maxDepth: 3,
244+
filterNode: 'script, style, [data-test-hide]'
245+
})
246+
```
247+
248+
#### Options
249+
250+
- **`maxDepth`** - Maximum depth to print nested elements (default: `Infinity`)
251+
- **`maxLength`** - Maximum length of the output string (default: `7000`)
252+
- **`filterNode`** - A CSS selector string or function to filter out nodes from the output. When a string is provided, elements matching the selector will be excluded. When a function is provided, it should return `false` to exclude a node.
253+
- **`highlight`** - Enable syntax highlighting (default: `true`)
254+
- And other options from [`pretty-format`](https://www.npmjs.com/package/@vitest/pretty-format)
255+
256+
#### Filtering with CSS Selectors <Version>4.1.0</Version> {#filtering-with-css-selectors}
257+
258+
The `filterNode` option allows you to hide irrelevant markup (like scripts, styles, or hidden elements) from test failure messages, making it easier to identify the actual cause of failures.
259+
260+
```ts
261+
import { utils } from 'vitest/browser'
262+
263+
// Filter out common noise elements
264+
utils.configurePrettyDOM({
265+
filterNode: 'script, style, [data-test-hide]'
266+
})
267+
268+
// Or use directly with prettyDOM
269+
const html = utils.prettyDOM(element, undefined, {
270+
filterNode: 'script, style'
271+
})
272+
```
273+
274+
**Common Patterns:**
275+
276+
Filter out scripts and styles:
277+
```ts
278+
utils.configurePrettyDOM({ filterNode: 'script, style' })
279+
```
280+
281+
Hide specific elements with data attributes:
282+
```ts
283+
utils.configurePrettyDOM({ filterNode: '[data-test-hide]' })
284+
```
285+
286+
Hide nested content within an element:
287+
```ts
288+
// Hides all children of elements with data-test-hide-content
289+
utils.configurePrettyDOM({ filterNode: '[data-test-hide-content] *' })
290+
```
291+
292+
Combine multiple selectors:
293+
```ts
294+
utils.configurePrettyDOM({
295+
filterNode: 'script, style, [data-test-hide], svg'
296+
})
297+
```
298+
299+
::: tip
300+
This feature is inspired by Testing Library's [`defaultIgnore`](https://testing-library.com/docs/dom-testing-library/api-configuration/#defaultignore) configuration.
301+
:::

docs/config/browser/playwright.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,35 @@ await userEvent.click(page.getByRole('button'), {
104104
timeout: 1_000,
105105
})
106106
```
107+
108+
## `persistentContext` <Version>4.1.0</Version> {#persistentcontext}
109+
110+
- **Type:** `boolean | string`
111+
- **Default:** `false`
112+
113+
When enabled, Vitest uses Playwright's [persistent context](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context) instead of a regular browser context. This allows browser state (cookies, localStorage, DevTools settings, etc.) to persist between test runs.
114+
115+
::: warning
116+
This option is ignored when running tests in parallel (e.g. when headless with [`fileParallelism`](/config/fileparallelism) enalbed) since persistent context cannot be shared across parallel sessions.
117+
:::
118+
119+
- When set to `true`, the user data is stored in `./node_modules/.cache/vitest-playwright-user-data`
120+
- When set to a string, the value is used as the path to the user data directory
121+
122+
```ts [vitest.config.js]
123+
import { playwright } from '@vitest/browser-playwright'
124+
import { defineConfig } from 'vitest/config'
125+
126+
export default defineConfig({
127+
test: {
128+
browser: {
129+
provider: playwright({
130+
persistentContext: true,
131+
// or specify a custom directory:
132+
// persistentContext: './my-browser-data',
133+
}),
134+
instances: [{ browser: 'chromium' }],
135+
},
136+
},
137+
})
138+
```

0 commit comments

Comments
 (0)