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
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.
- 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.
This feature is inspired by Testing Library's [`defaultIgnore`](https://testing-library.com/docs/dom-testing-library/api-configuration/#defaultignore) configuration.
Copy file name to clipboardExpand all lines: docs/api/vi.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,8 @@ function mock<T>(
37
37
38
38
Substitutesallimportedmodulesfromprovided`path`withanothermodule. YoucanuseconfiguredVitealiasesinsideapath. Thecallto`vi.mock`ishoisted, soitdoesn'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`.
39
39
40
+
Itisrecommendedtouse`vi.mock`or`vi.hoisted`onlyinsidetestfiles. IfVite'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
+
40
42
::: warning
41
43
`vi.mock`worksonlyformodulesthatwereimportedwiththe`import`keyword. Itdoesn't work with `require`.
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
0 commit comments