Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
71e31a5
feat(browser): add failure-only trace view mode
hi-ogawa Oct 16, 2026
560f72c
Merge remote-tracking branch 'upstream/main' into fix/issue-10310
hi-ogawa Oct 20, 2026
c02c7f1
test(browser): cover failure-only trace timeline output
hi-ogawa Oct 20, 2026
e3a26aa
docs: describe trace view mode as which tests keep a trace
hi-ogawa Oct 20, 2026
aecf8cf
docs: describe trace view modes by which tests get a trace
hi-ogawa Oct 20, 2026
220d014
docs: summarize trace view mode as how tests are recorded
hi-ogawa Oct 20, 2026
92b2ac3
feat(browser): deprecate traceView.enabled in favor of mode
hi-ogawa Oct 20, 2026
61adf55
refactor: keep resolved traceView type as is
hi-ogawa Oct 20, 2026
01cc417
perf(browser): load rrweb only at the first failure in failure-only mode
hi-ogawa Oct 20, 2026
098f6b3
refactor(browser): read rrweb from the orchestrator loader directly
hi-ogawa Oct 20, 2026
296ca72
refactor(browser): build trace entry once for both modes
hi-ogawa Oct 20, 2026
f2c1e24
test(browser): drop redundant failure-only coverage
hi-ogawa Oct 20, 2026
84b1a8e
refactor(browser): send failure-only trace with the failed test end e…
hi-ogawa Oct 20, 2026
97e3365
refactor(browser): create failure-only trace buffer lazily
hi-ogawa Oct 20, 2026
9d1539e
test(ui): cover failure-only trace in ui and html reporter
hi-ogawa Oct 20, 2026
871426e
test(ui): combine failure-only trace checks
hi-ogawa Oct 20, 2026
25480a6
test(ui): narrate failure-only trace steps
hi-ogawa Oct 20, 2026
ad4412c
refactor(browser): name the snapshot condition
hi-ogawa Oct 20, 2026
394809a
fix(browser): keep the details panel position in failure-only mode
hi-ogawa Oct 21, 2026
610a724
Revert "fix(browser): keep the details panel position in failure-only…
hi-ogawa Oct 21, 2026
88ca9c3
feat(browser): enable failure-only trace view by default
hi-ogawa Oct 21, 2026
8dfe6ef
fix(browser): keep the details panel position by default
hi-ogawa Oct 21, 2026
fe4345d
test: cover failure-only trace view default
hi-ogawa Oct 21, 2026
b919a35
test: assert trace view defaults in input order
hi-ogawa Oct 21, 2026
3f2387e
feat(browser): warn on deprecated traceView.enabled
hi-ogawa Oct 26, 2026
d13fb3e
Merge remote-tracking branch 'origin/fix/issue-10310' into feat/trace…
hi-ogawa Oct 26, 2026
be73c38
feat(browser): accept mode in --browser.traceView
hi-ogawa Oct 26, 2026
5fde745
Merge remote-tracking branch 'origin/fix/issue-10310' into feat/trace…
hi-ogawa Oct 26, 2026
bf11873
docs: update --browser.traceView default
hi-ogawa Oct 26, 2026
778070e
refactor(cli): drop yes/no for --browser.traceView
hi-ogawa Oct 26, 2026
5276171
Merge remote-tracking branch 'origin/fix/issue-10310' into feat/trace…
hi-ogawa Oct 26, 2026
28bc78b
revert(cli): keep --browser.traceView boolean
hi-ogawa Oct 26, 2026
4cf9ef8
Merge remote-tracking branch 'origin/fix/issue-10310' into feat/trace…
hi-ogawa Oct 26, 2026
7a136a9
Merge remote-tracking branch 'upstream/main' into feat/trace-view-fai…
hi-ogawa Oct 26, 2026
22ab98e
docs: suggest html reporter for failure-only traces
hi-ogawa Oct 26, 2026
2918d44
docs: simplify trace view default and failure output prose
hi-ogawa Oct 26, 2026
9f222a5
docs: describe failure-only default in trace view guide
hi-ogawa Oct 26, 2026
404c362
docs: clarify failure-only keeps one snapshot
hi-ogawa Oct 26, 2026
fefdb1f
docs: name trace view mode where snapshots differ
hi-ogawa Oct 26, 2026
60603e6
docs: trim reporter flags from trace view guide
hi-ogawa Oct 26, 2026
31f9469
fix(browser): update trace view CLI defaults
hi-ogawa Oct 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions docs/config/browser/traceview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,17 @@ outline: deep

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

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

```ts
export default defineConfig({
test: {
browser: {
traceView: true,
},
},
})
```

To keep traces only for failed tests, use the `'failure-only'` mode:
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:

```ts
export default defineConfig({
test: {
browser: {
traceView: 'failure-only',
traceView: true,
},
},
})
Expand All @@ -49,13 +39,13 @@ export default defineConfig({
})
```

| Option | Default | Description |
| -------------- | ------- | ---------------------------------------------------------------------------------------------------- |
| `mode` | `'off'` | How trace view records tests: `'on'` (every test), `'failure-only'` (only failed tests), or `'off'`. |
| `inlineImages` | `false` | Inlines loaded `<img>` pixels into snapshots for more portable replay, useful in the HTML reporter. |
| `recordCanvas` | `false` | Captures canvas pixels in snapshots. |
| `ariaSnapshot` | `true` | Captures the accessibility tree alongside each snapshot. |
| `enabled` | `false` | Deprecated. Use `mode` instead. |
| Option | Default | Description |
| -------------- | ---------------- | ---------------------------------------------------------------------------------------------------- |
| `mode` | `'failure-only'` | How trace view records tests: `'on'` (every test), `'failure-only'` (only failed tests), or `'off'`. |
| `inlineImages` | `false` | Inlines loaded `<img>` pixels into snapshots for more portable replay, useful in the HTML reporter. |
| `recordCanvas` | `false` | Captures canvas pixels in snapshots. |
| `ariaSnapshot` | `true` | Captures the accessibility tree alongside each snapshot. |
| `enabled` | `false` | Deprecated. Use `mode` instead. |

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

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

- **Type:** `'off' | 'on' | 'failure-only'`
- **Default:** `'off'`
- **Default:** `'failure-only'`
- **CLI:** `--browser.traceView.mode <mode>`

How trace view records tests. Takes precedence over the deprecated `enabled`.
Expand Down
18 changes: 9 additions & 9 deletions docs/guide/browser/trace-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

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

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

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

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.

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

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.

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

## Quick Start

Enable trace view with the [`browser.traceView`](/config/browser/traceview) option:
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:

::: code-group

Expand All @@ -44,7 +44,7 @@ vitest --browser.traceView

:::

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

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.

Expand Down Expand Up @@ -77,11 +77,11 @@ TODO: The browser UI / Vitest UI / browser driver combinations are not specific

| Goal | Configuration | Result |
| --------------------------------------------------------- | ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |

## Relation to Playwright Traces

Expand Down Expand Up @@ -114,7 +114,7 @@ When a test fails, the error in the terminal is followed by a timeline of its re

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

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

## Custom Trace Entries

Expand Down Expand Up @@ -177,7 +177,7 @@ export default defineConfig({
test: {
browser: {
traceView: {
enabled: true,
mode: 'on',
inlineImages: true,
recordCanvas: true,
},
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/cli-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,14 @@ Enable trace view mode. Supported: "on", "off", "on-first-retry", "on-all-retrie
- **CLI:** `--browser.traceView.enabled`
- **Config:** [browser.traceView.enabled](/config/browser/traceview#traceview-enabled)

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

### browser.traceView.mode

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

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

### browser.traceView.recordCanvas

Expand Down
7 changes: 4 additions & 3 deletions packages/vitest/src/node/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ export const cliOptionsConfig: VitestCLIOptions = {
},
},
traceView: {
description: 'Enable Vitest trace-view collection for browser tests (default: `false`)',
description:
'Enable Vitest trace-view collection for browser tests. `true` records every test, and `false` turns it off (default: `"failure-only"`)',
argument: '',
transform(value) {
if (typeof value === 'boolean') {
Expand All @@ -426,11 +427,11 @@ export const cliOptionsConfig: VitestCLIOptions = {
subcommands: {
enabled: {
description:
'Deprecated, use `--browser.traceView.mode` instead. Enable Vitest trace-view collection for browser tests (default: `false`)',
'Deprecated, use `--browser.traceView.mode` instead. `true` is the same as `--browser.traceView.mode=on`',
},
mode: {
description:
'How trace view records tests. Supported: "on" (every test), "failure-only" (only failed tests), "off" (default: `"off"`)',
'How trace view records tests. Supported: "on" (every test), "failure-only" (only failed tests), "off" (default: `"failure-only"`)',
argument: '<mode>',
},
recordCanvas: {
Expand Down
13 changes: 8 additions & 5 deletions packages/vitest/src/node/config/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,18 +964,21 @@ export function resolveTestConfig(
typeof traceView === 'string'
? traceView
: typeof traceView === 'object'
? (traceView.mode ?? (traceView.enabled ? 'on' : 'off'))
: traceView
? 'on'
: 'off'
? (traceView.mode ??

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magnificent

(traceView.enabled === undefined ? 'failure-only' : traceView.enabled ? 'on' : 'off'))
: traceView === undefined
? 'failure-only'
: traceView
? 'on'
: 'off'
resolved.browser.traceView = {
enabled: traceViewMode !== 'off',
mode: traceViewMode,
recordCanvas: traceViewOptions?.recordCanvas ?? false,
inlineImages: traceViewOptions?.inlineImages ?? false,
ariaSnapshot: traceViewOptions?.ariaSnapshot ?? true,
}
if (resolved.browser.enabled && resolved.browser.traceView.enabled) {
if (resolved.browser.enabled && resolved.browser.traceView.mode === 'on') {
resolved.browser.detailsPanelPosition = 'bottom'
}
if (resolved.browser.trace.tracesDir != null) {
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/types/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export interface BrowserTraceViewOptions {
*
* Takes precedence over `enabled`.
*
* @default 'off'
* @default 'failure-only'
* @experimental
*/
mode?: BrowserTraceViewRecordingMode
Expand Down Expand Up @@ -297,7 +297,7 @@ export interface BrowserConfigOptions {
*
* This option controls Vitest's own trace-view pipeline, independently from provider-specific trace retention.
*
* @default false
* @default 'failure-only'
*/
traceView?: boolean | BrowserTraceViewRecordingMode | BrowserTraceViewOptions

Expand Down
1 change: 0 additions & 1 deletion test/browser/specs/trace-timeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ async function runBrowserTests(structure: TestFsStructure) {
browser: {
ui: false,
instances: instances.slice(0, 1),
traceView: true,
screenshotFailures: false,
},
})
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/test/config/browser-configs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,33 @@ test('detailsPanelPosition defaults to right', async () => {
expect(projects[0].projectConfig.browser.detailsPanelPosition).toBe('right')
})

test('traceView defaults to failure-only', async () => {
const resolveMode = async (traceView?: NonNullable<TestUserConfig['browser']>['traceView']) => {
const projects = await config({
browser: {
enabled: true,
provider: preview(),
instances: [{ browser: 'chromium' }],
...(traceView === undefined ? {} : { traceView }),
},
})
return projects[0].projectConfig.browser.traceView.mode
}
expect({
default: await resolveMode(),
true: await resolveMode(true),
false: await resolveMode(false),
object: await resolveMode({ inlineImages: true }),
enabled: await resolveMode({ enabled: true }),
}).toEqual({
default: 'failure-only',
true: 'on',
false: 'off',
object: 'failure-only',
enabled: 'on',
})
})

test('detailsPanelPosition from config file is respected', async () => {
const projects = await config({
browser: {
Expand Down
Loading