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
{{ message }}
Repository navigation
Commit f37b6b7
Browse filesBrowse the repository at this point in the historyBrowse files
Enable [trace view](/guide/browser/trace-view) collection for browser tests. Vitest captures DOM snapshots for browser interactions and can show them in the browser UI, Vitest UI, or HTML reporter when those surfaces are enabled — no external tools required. When a test fails, the terminal output also includes a [timeline of its recorded steps](/guide/browser/trace-view#failure-output).
13
13
14
-
```ts
15
-
exportdefaultdefineConfig({
16
-
test: {
17
-
browser: {
18
-
traceView: true,
19
-
},
20
-
},
21
-
})
22
-
```
23
-
24
-
To keep traces only for failed tests, use the `'failure-only'` mode:
14
+
By default, trace view keeps traces only for failed tests. Set it to `true` (the same as [`mode: 'on'`](#traceview-mode)) to record every test, or `false` to turn it off:
Copy file name to clipboardExpand all lines: docs/guide/browser/trace-view.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,13 @@
2
2
3
3
`browser.traceView` records browser interactions as DOM snapshots and lets you replay them step by step in Vitest's built-in trace viewer. It is useful when the live browser view is not enough: you can inspect earlier tests, failed retries, screenshots, assertions, and user actions after the browser has already moved on.
4
4
5
-
Trace view is additive to the current browser testing workflow. Enabling it does not force a single debugging mode. You can use it with the normal local browser UI, with a headless browser and Vitest UI, or with the HTML reporter in CI. When a test fails, the terminal output also includes a text timeline of its recorded steps.
5
+
By default, Vitest records traces only for failed tests, so every browser test failure prints a [timeline of its recorded steps](#failure-output) in the terminal. The trace keeps a DOM snapshot of the page when the test failed, which you can open in the browser UI, Vitest UI, or HTML reporter. To snapshot every step, set [`browser.traceView.mode`](/config/browser/traceview#traceview-mode) to `'on'`. Trace view works with your existing debugging setup, whether that is the normal local browser UI, a headless browser with Vitest UI, or the HTML reporter in CI.
6
6
7
7
::: tip Trace view, browser UI, and HTML reports
8
8
9
9
The normal local browser mode opens the [browser UI](/config/browser/ui), where tests run in a visible iframe. This is useful while developing, but the iframe only shows the current browser state. When another test runs, the previous rendered state is gone.
10
10
11
-
`browser.traceView` keeps a replayable record for each test. In local browser UI mode, the trace viewer appears alongside the existing live view so you can keep using the browser UI while also inspecting recorded steps.
11
+
`browser.traceView` keeps a replayable record for each recorded test. In local browser UI mode, the trace viewer appears alongside the existing live view so you can keep using the browser UI while also inspecting recorded steps.
12
12
13
13
For static output, add the [HTML reporter](/guide/reporters#html-reporter). The same trace viewer can then be opened from the generated report, which is useful for run-mode and CI failures.
14
14
@@ -22,7 +22,7 @@ This page now documents Vitest's built-in `browser.traceView` feature. The previ
22
22
23
23
## Quick Start
24
24
25
-
Enable trace view with the [`browser.traceView`](/config/browser/traceview) option:
25
+
Failed tests are recorded without any configuration. To record passing tests too, set the [`browser.traceView`](/config/browser/traceview) option to `true`, or set it to `false` to turn trace view off:
26
26
27
27
::: code-group
28
28
@@ -44,7 +44,7 @@ vitest --browser.traceView
44
44
45
45
:::
46
46
47
-
When `browser.traceView` is enabled, tests with recorded traces can be opened in the trace viewer from the [browser UI](/config/browser/ui), [Vitest UI](/guide/ui), and [HTML reporter](/guide/reporters#html-reporter). Failed tests also print their recorded steps in the terminal, as described in [Failure Output](#failure-output).
47
+
Tests with recorded traces can be opened in the trace viewer from the [browser UI](/config/browser/ui), [Vitest UI](/guide/ui), and [HTML reporter](/guide/reporters#html-reporter). Failed tests also print their recorded steps in the terminal, as described in [Failure Output](#failure-output).
48
48
49
49
With the HTML reporter enabled, the [Vitest VS Code extension](https://github.com/vitest-dev/vscode#trace-view) adds an **Open Trace View** action to tests in the Testing view and editor gutter.
50
50
@@ -66,11 +66,11 @@ Selecting a step also opens its source location in the Editor tab when that loca
| Add trace replay to the normal local browser UI |`vitest --browser.traceView`| Uses the default local headed browser UI and adds trace replay for recorded tests.|
69
+
| Add trace replay to the normal local browser UI |`vitest --browser.traceView`| Uses the default local headed browser UI and adds trace replay for every test. |
70
70
| Debug locally with a headless browser |`vitest --browser.traceView --browser.headless --ui`| The browser runs headless, while Vitest UI shows recorded trace steps and snapshots. |
71
71
| Debug locally with a visible browser window and Vitest UI |`vitest --browser.traceView --browser.headless=false --browser.ui=false --ui`| Vitest UI shows recorded trace steps and snapshots, while tests run in a separate headed browser window. |
72
-
|Generate a static report for CI or run mode |`vitest run --browser.traceView --reporter=html`| The HTML report includes the trace viewer for recorded tests.|
73
-
|See failure steps in CI logs or from a coding agent|`vitest run --browser.traceView`| The failure summary in the terminal includes a timeline of the steps that led to each failure.|
72
+
|See failure steps in CI logs or from a coding agent|`vitest run`| The failure summary in the terminal includes a timeline of the steps that led to each failure.|
73
+
|Inspect failures in CI or run mode |`vitest run --reporter=html`| The HTML report shows the full step list with the page when the test failed. |
74
74
75
75
## Relation to Playwright Traces
76
76
@@ -103,7 +103,7 @@ When a test fails, the error in the terminal is followed by a timeline of its re
103
103
104
104
<<< ./snippets/trace-failure.ansi [Error report]
105
105
106
-
These are the same steps the trace viewer lists, without DOM snapshots. Only the last 10 steps are printed, so open the trace viewer to see the full trace.
106
+
These are the last 10 steps the trace viewer lists, without DOM snapshots. To inspect the full step list and the page when the test failed, add the [HTML reporter](/guide/reporters#html-reporter). Set [`browser.traceView.mode`](/config/browser/traceview#traceview-mode)to `'on'` to snapshot every step.
0 commit comments