Skip to content

Commit 6bafe40

Browse files
authored
Merge branch 'main' into copilot/add-known-failing-tests-support
2 parents 7df9d08 + 2a60cf8 commit 6bafe40

167 files changed

Lines changed: 6088 additions & 1365 deletions

File tree

Some content is hidden

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

docs/.vitepress/components/ListItem.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ function reset() {
1919
const color = computed(() => {
2020
return {
2121
'--vp-c-brand-1': state.value === 1
22-
? '#66ba1c'
22+
? 'var(--color-brand)'
2323
: state.value === 2
24-
? 'rgba(248, 113, 113)'
25-
: 'rgba(250, 204, 21)',
24+
? 'var(--vp-c-red-1)'
25+
: 'var(--vp-c-yellow-1)',
2626
} as any
2727
})
2828
@@ -42,7 +42,9 @@ onMounted(async () => {
4242
<li :style="color">
4343
<div ref="el" class="icon-container">
4444
<div class="icon-wrapper" :class="state ? 'flip' : ''">
45-
<Icon icon="carbon:circle-dash" class="icon-spinner" width="1.2em" height="1.2em" />
45+
<svg xmlns="http://www.w3.org/2000/svg" width="1.2em" height="1.2em" viewBox="0 0 32 32" class="icon-spinner">
46+
<circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2" stroke-dasharray="8 4" />
47+
</svg>
4648
</div>
4749
<div class="icon-wrapper" :class="state === 2 ? '' : 'flip'">
4850
<Icon icon="carbon:close-outline" class="icon-error" width="1.2em" height="1.2em" />
@@ -79,15 +81,15 @@ onMounted(async () => {
7981
8082
.icon-spinner {
8183
animation: spin 1s linear infinite;
82-
color: rgb(250, 204, 21);
84+
color: var(--vp-c-yellow-1);
8385
}
8486
8587
.icon-error {
86-
color: rgb(248, 113, 113);
88+
color: var(--vp-c-red-1);
8789
}
8890
8991
.icon-success {
90-
color: var(--vp-c-brand-1);
92+
color: var(--color-brand);
9193
}
9294
9395
@keyframes spin {

docs/.vitepress/config.ts

Lines changed: 0 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'
@@ -80,17 +79,11 @@ export default ({ mode }: { mode: string }) => {
8079
groupIconVitePlugin({
8180
customIcon: {
8281
'CLI': 'vscode-icons:file-type-shell',
83-
'vitest.shims': localIconLoader(import.meta.url, '../public/logo-without-border.svg'),
84-
'vitest.config': localIconLoader(import.meta.url, '../public/logo-without-border.svg'),
85-
'vitest.workspace': localIconLoader(import.meta.url, '../public/logo-without-border.svg'),
8682
'.spec.ts': 'vscode-icons:file-type-testts',
8783
'.test.ts': 'vscode-icons:file-type-testts',
8884
'.spec.js': 'vscode-icons:file-type-testjs',
8985
'.test.js': 'vscode-icons:file-type-testjs',
90-
'marko': 'vscode-icons:file-type-marko',
91-
'qwik': 'logos:qwik-icon',
9286
'next': '',
93-
'vite.config': localIconLoader(import.meta.url, '../public/logo-without-border-vite.svg'),
9487
},
9588
}),
9689
llmstxt(),

docs/.vitepress/theme/styles.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@
55
/* Vitest */
66
:root[data-variant="vitest"] {
77
--color-brand: #008039;
8+
/* TODO: home page wcag-aa color contrast (remove this once fixed at void0 theme):
9+
* - why vitest section and texts
10+
* - vitest, resources, versions and social
11+
* - footer
12+
*/
13+
--color-grey: #867e8e;
814
}
915

1016
:root.dark:not([data-theme])[data-variant="vitest"],
1117
:root[data-theme="dark"][data-variant="vitest"] {
1218
--color-brand: var(--color-zest);
1319
}
1420

21+
:root[data-variant="vitest"]:not(.dark):not([data-theme="light"]),
1522
:root[data-theme="light"][data-variant="vitest"] {
1623
--color-brand: #008039;
24+
/* TODO: code block (remove this once fixed at void0 theme) */
25+
--vp-code-color: #007d38;
1726
}
1827

1928

@@ -48,4 +57,4 @@ html:not(.dark) .VPContent kbd {
4857
padding: 2px 5px;
4958
position: relative;
5059
top: -1px;
51-
}
60+
}

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/api/vi.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ function mock<T>(
3737

3838
Substitutes all imported modules from provided `path` with another module. You can use configured Vite aliases inside a path. The call to `vi.mock` is hoisted, so it doesn't matter where you call it. It will always be executed before all imports. If you need to reference some variables outside of its scope, you can define them inside [`vi.hoisted`](#vi-hoisted) and reference them inside `vi.mock`.
3939

40+
It is recommended to use `vi.mock` or `vi.hoisted` only inside test files. If Vite's [module runner](/config/experimental#experimental-vitemodulerunner) is disabled, they will not be hoisted. This is a performance optimisation to avoid ready unnecessary files.
41+
4042
::: warning
4143
`vi.mock` works only for modules that were imported with the `import` keyword. It doesn't work with `require`.
4244

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)