Skip to content

Commit f37b6b7

Browse files
hi-ogawaclaude
andauthored
feat(browser): enable failure-only trace view by default (#11766)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 2bc2041 commit f37b6b7

8 files changed

Lines changed: 63 additions & 43 deletions

File tree

‎docs/config/browser/traceview.md‎

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,17 @@ outline: deep
77

88
- **Type:** `boolean | 'off' | 'on' | 'failure-only' | { mode?: 'off' | 'on' | 'failure-only'; recordCanvas?: boolean; inlineImages?: boolean; ariaSnapshot?: boolean }`
99
- **CLI:** `--browser.traceView`
10-
- **Default:** `false`
10+
- **Default:** `'failure-only'`
1111

1212
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).
1313

14-
```ts
15-
export default defineConfig({
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:
2515

2616
```ts
2717
export default defineConfig({
2818
test: {
2919
browser: {
30-
traceView: 'failure-only',
20+
traceView: true,
3121
},
3222
},
3323
})
@@ -49,13 +39,13 @@ export default defineConfig({
4939
})
5040
```
5141

52-
| Option | Default | Description |
53-
| -------------- | ------- | ---------------------------------------------------------------------------------------------------- |
54-
| `mode` | `'off'` | How trace view records tests: `'on'` (every test), `'failure-only'` (only failed tests), or `'off'`. |
55-
| `inlineImages` | `false` | Inlines loaded `<img>` pixels into snapshots for more portable replay, useful in the HTML reporter. |
56-
| `recordCanvas` | `false` | Captures canvas pixels in snapshots. |
57-
| `ariaSnapshot` | `true` | Captures the accessibility tree alongside each snapshot. |
58-
| `enabled` | `false` | Deprecated. Use `mode` instead. |
42+
| Option | Default | Description |
43+
| -------------- | ---------------- | ---------------------------------------------------------------------------------------------------- |
44+
| `mode` | `'failure-only'` | How trace view records tests: `'on'` (every test), `'failure-only'` (only failed tests), or `'off'`. |
45+
| `inlineImages` | `false` | Inlines loaded `<img>` pixels into snapshots for more portable replay, useful in the HTML reporter. |
46+
| `recordCanvas` | `false` | Captures canvas pixels in snapshots. |
47+
| `ariaSnapshot` | `true` | Captures the accessibility tree alongside each snapshot. |
48+
| `enabled` | `false` | Deprecated. Use `mode` instead. |
5949

6050
## browser.traceView.enabled <Deprecated /> {#traceview-enabled}
6151

@@ -68,7 +58,7 @@ Use [`mode`](#traceview-mode) instead. `true` is the same as `mode: 'on'`.
6858
## browser.traceView.mode <Version>5.1.0</Version> {#traceview-mode}
6959

7060
- **Type:** `'off' | 'on' | 'failure-only'`
71-
- **Default:** `'off'`
61+
- **Default:** `'failure-only'`
7262
- **CLI:** `--browser.traceView.mode <mode>`
7363

7464
How trace view records tests. Takes precedence over the deprecated `enabled`.

‎docs/guide/browser/trace-view.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
`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.
44

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.
66

77
::: tip Trace view, browser UI, and HTML reports
88

99
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.
1010

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.
1212

1313
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.
1414

@@ -22,7 +22,7 @@ This page now documents Vitest's built-in `browser.traceView` feature. The previ
2222

2323
## Quick Start
2424

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:
2626

2727
::: code-group
2828

@@ -44,7 +44,7 @@ vitest --browser.traceView
4444

4545
:::
4646

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).
4848

4949
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.
5050

@@ -66,11 +66,11 @@ Selecting a step also opens its source location in the Editor tab when that loca
6666

6767
| Goal | Configuration | Result |
6868
| --------------------------------------------------------- | ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
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 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. |
7070
| 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. |
7171
| 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. |
7474

7575
## Relation to Playwright Traces
7676

@@ -103,7 +103,7 @@ When a test fails, the error in the terminal is followed by a timeline of its re
103103

104104
<<< ./snippets/trace-failure.ansi [Error report]
105105

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.
107107

108108
## Custom Trace Entries
109109

@@ -166,7 +166,7 @@ export default defineConfig({
166166
test: {
167167
browser: {
168168
traceView: {
169-
enabled: true,
169+
mode: 'on',
170170
inlineImages: true,
171171
recordCanvas: true,
172172
},

‎docs/guide/cli-generated.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,14 @@ Enable trace view mode. Supported: "on", "off", "on-first-retry", "on-all-retrie
414414
- **CLI:** `--browser.traceView.enabled`
415415
- **Config:** [browser.traceView.enabled](/config/browser/traceview#traceview-enabled)
416416

417-
Deprecated, use `--browser.traceView.mode` instead. Enable Vitest trace-view collection for browser tests (default: `false`)
417+
Deprecated, use `--browser.traceView.mode` instead. `true` is the same as `--browser.traceView.mode=on`
418418

419419
### browser.traceView.mode
420420

421421
- **CLI:** `--browser.traceView.mode <mode>`
422422
- **Config:** [browser.traceView.mode](/config/browser/traceview#traceview-mode)
423423

424-
How trace view records tests. Supported: "on" (every test), "failure-only" (only failed tests), "off" (default: `"off"`)
424+
How trace view records tests. Supported: "on" (every test), "failure-only" (only failed tests), "off" (default: `"failure-only"`)
425425

426426
### browser.traceView.recordCanvas
427427

‎packages/vitest/src/node/cli/cli-config.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ export const cliOptionsConfig: VitestCLIOptions = {
415415
},
416416
},
417417
traceView: {
418-
description: 'Enable Vitest trace-view collection for browser tests (default: `false`)',
418+
description:
419+
'Enable Vitest trace-view collection for browser tests. `true` records every test, and `false` turns it off (default: `"failure-only"`)',
419420
argument: '',
420421
transform(value) {
421422
if (typeof value === 'boolean') {
@@ -426,11 +427,11 @@ export const cliOptionsConfig: VitestCLIOptions = {
426427
subcommands: {
427428
enabled: {
428429
description:
429-
'Deprecated, use `--browser.traceView.mode` instead. Enable Vitest trace-view collection for browser tests (default: `false`)',
430+
'Deprecated, use `--browser.traceView.mode` instead. `true` is the same as `--browser.traceView.mode=on`',
430431
},
431432
mode: {
432433
description:
433-
'How trace view records tests. Supported: "on" (every test), "failure-only" (only failed tests), "off" (default: `"off"`)',
434+
'How trace view records tests. Supported: "on" (every test), "failure-only" (only failed tests), "off" (default: `"failure-only"`)',
434435
argument: '<mode>',
435436
},
436437
recordCanvas: {

‎packages/vitest/src/node/config/resolveConfig.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -964,18 +964,21 @@ export function resolveTestConfig(
964964
typeof traceView === 'string'
965965
? traceView
966966
: typeof traceView === 'object'
967-
? (traceView.mode ?? (traceView.enabled ? 'on' : 'off'))
968-
: traceView
969-
? 'on'
970-
: 'off'
967+
? (traceView.mode ??
968+
(traceView.enabled === undefined ? 'failure-only' : traceView.enabled ? 'on' : 'off'))
969+
: traceView === undefined
970+
? 'failure-only'
971+
: traceView
972+
? 'on'
973+
: 'off'
971974
resolved.browser.traceView = {
972975
enabled: traceViewMode !== 'off',
973976
mode: traceViewMode,
974977
recordCanvas: traceViewOptions?.recordCanvas ?? false,
975978
inlineImages: traceViewOptions?.inlineImages ?? false,
976979
ariaSnapshot: traceViewOptions?.ariaSnapshot ?? true,
977980
}
978-
if (resolved.browser.enabled && resolved.browser.traceView.enabled) {
981+
if (resolved.browser.enabled && resolved.browser.traceView.mode === 'on') {
979982
resolved.browser.detailsPanelPosition = 'bottom'
980983
}
981984
if (resolved.browser.trace.tracesDir != null) {

‎packages/vitest/src/node/types/browser.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export interface BrowserTraceViewOptions {
9292
*
9393
* Takes precedence over `enabled`.
9494
*
95-
* @default 'off'
95+
* @default 'failure-only'
9696
* @experimental
9797
*/
9898
mode?: BrowserTraceViewRecordingMode
@@ -297,7 +297,7 @@ export interface BrowserConfigOptions {
297297
*
298298
* This option controls Vitest's own trace-view pipeline, independently from provider-specific trace retention.
299299
*
300-
* @default false
300+
* @default 'failure-only'
301301
*/
302302
traceView?: boolean | BrowserTraceViewRecordingMode | BrowserTraceViewOptions
303303

‎test/browser/specs/trace-timeline.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ async function runBrowserTests(structure: TestFsStructure) {
88
browser: {
99
ui: false,
1010
instances: instances.slice(0, 1),
11-
traceView: true,
1211
screenshotFailures: false,
1312
},
1413
})

‎test/e2e/test/config/browser-configs.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,33 @@ test('detailsPanelPosition defaults to right', async () => {
817817
expect(projects[0].projectConfig.browser.detailsPanelPosition).toBe('right')
818818
})
819819

820+
test('traceView defaults to failure-only', async () => {
821+
const resolveMode = async (traceView?: NonNullable<TestUserConfig['browser']>['traceView']) => {
822+
const projects = await config({
823+
browser: {
824+
enabled: true,
825+
provider: preview(),
826+
instances: [{ browser: 'chromium' }],
827+
...(traceView === undefined ? {} : { traceView }),
828+
},
829+
})
830+
return projects[0].projectConfig.browser.traceView.mode
831+
}
832+
expect({
833+
default: await resolveMode(),
834+
true: await resolveMode(true),
835+
false: await resolveMode(false),
836+
object: await resolveMode({ inlineImages: true }),
837+
enabled: await resolveMode({ enabled: true }),
838+
}).toEqual({
839+
default: 'failure-only',
840+
true: 'on',
841+
false: 'off',
842+
object: 'failure-only',
843+
enabled: 'on',
844+
})
845+
})
846+
820847
test('detailsPanelPosition from config file is respected', async () => {
821848
const projects = await config({
822849
browser: {

0 commit comments

Comments
 (0)