-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser): support dom snapshot trace view #10102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hi-ogawa
wants to merge
152
commits into
vitest-dev:main
Choose a base branch
from
hi-ogawa:wip-builtin-trace-system
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
152 commits
Select commit
Hold shift + click to select a range
0dfa175
wip: builtin trace system
hi-ogawa 1e08082
wip: de-slop
hi-ogawa 250e24c
wip: de-slop
hi-ogawa 625a3ba
refactor: de slop
hi-ogawa 55f840f
refactor: rename
hi-ogawa d212deb
refactor: de slop
hi-ogawa bbcc1b5
wip: fix global
hi-ogawa 45addf2
wip: snapshot and rebuild
hi-ogawa c1f91f2
fix: bundle and lazy load rrweb-snapshot
hi-ogawa f133f04
wip: delay page.mark(function) trace
hi-ogawa 0889f0e
refactor: remove dup types
hi-ogawa 2fb9330
chore: todo
hi-ogawa 5775533
fix: trace action
hi-ogawa 71e2b80
Merge branch 'main' into wip-builtin-trace-system
hi-ogawa 076d29c
chore: todo
hi-ogawa 965f518
wip: trace action with selector
hi-ogawa 2522b94
fix: record snapshot with css selector
hi-ogawa 33d81d4
Merge remote-tracking branch 'origin/wip-builtin-trace-system' into w…
hi-ogawa ca7bf2a
wip: use rrweb Mirror for element highlight (nodeId-based, shadow DOM…
hi-ogawa 846e940
refactor: de slop
hi-ogawa 91f0bcb
wip: overlay-based element highlight in TraceView
hi-ogawa f755239
chore: ignore html
hi-ogawa 7a1db8b
refactor: nit
hi-ogawa f5e5c33
wip: server-side stack resolution + source location in TraceView
hi-ogawa 95b314f
chore: todo
hi-ogawa ef35e94
feat(ui): start trace viewer layout
hi-ogawa 0dfff60
feat(ui): add trace view pane header
hi-ogawa cf105a3
chore: todo
hi-ogawa 31002de
chore: todo
hi-ogawa 9f6db30
feat(ui): default trace layout to bottom
hi-ogawa 63057c1
chore: todo
hi-ogawa 8cee41f
wip: link code view -> trace view
hi-ogawa 8f2e5fe
Revert "wip: link code view -> trace view"
hi-ogawa ef4fc52
chore: todo
hi-ogawa c0d9054
feat(browser): record trace artifact per attempt
hi-ogawa b3bd803
fix(ui): sync trace step on location click
hi-ogawa b446889
feat(ui): show trace selectors in step list
hi-ogawa 049c9e1
chore: remove todo
hi-ogawa 9edfde2
feat(browser): add traceView workflow state
hi-ogawa ba3bc5d
wip: auto open trace
hi-ogawa 89f56d6
chore: lint
hi-ogawa 8092086
test: check env.TEST_BROWSER for ui open
hi-ogawa 23e34f1
test: remove stale config
hi-ogawa 6ceda6b
wip: add html reporter by default
hi-ogawa 38aa974
fix: force traceView -> ui on watch
hi-ogawa 51736a4
chore: remove todo
hi-ogawa a11a34c
fix: cli config
hi-ogawa 345fc36
Merge branch 'main' into wip-builtin-trace-system
hi-ogawa f9e2c11
Merge remote-tracking branch 'origin/wip-builtin-trace-system' into w…
hi-ogawa 1d6647a
test: dog-fooding in packages/ui
hi-ogawa 2de7ac2
deslop
hi-ogawa e14bf26
chore: todo
hi-ogawa d1d44ec
deslop
hi-ogawa ab5c12a
test: other providers in packages/ui
hi-ogawa 108f7bd
docs: wip trace-view-v2
hi-ogawa 7660820
docs: draft trace-view guide for browser.traceView
hi-ogawa 782af47
docs: add rrweb link in trace-view guide
hi-ogawa 6dbe6aa
wip docs
hi-ogawa bc4d016
fix: fix webdriverio selector highlight
hi-ogawa 434a05b
fix: preview provide also works (somehow)
hi-ogawa de0464b
docs: todo
hi-ogawa 9029255
docs: improve framing of trace-view-v2 guide
hi-ogawa 2531ed1
docs: cross-link browser UI model with trace-view-v2 guide
hi-ogawa c9c70e1
docs: restructure trace-view-v2 and add screenshots
hi-ogawa 7fa86d3
docs: tweak
hi-ogawa 1a87005
docs: fix dead links in trace-view-v2 and add browser.traceView confi…
hi-ogawa 324df4f
wip: remove auto config logic
hi-ogawa 7784acd
docs: clarify trace view setup
hi-ogawa 4c4fd32
docs: simplify trace view workflow guidance
hi-ogawa 5820b2c
chore: todo
hi-ogawa b390c24
docs: tweak
hi-ogawa 186ec08
docs: expand trace view setup examples
hi-ogawa 273c1be
fix: fix browserIframe remount on trace select
hi-ogawa d5a947a
Merge branch 'main' into wip-builtin-trace-system
hi-ogawa e58dd00
wip: SerializedRootConfig
hi-ogawa 9ca27c6
fix/refactor: pass serializeRootConfig to UI
hi-ogawa d180500
fix: fix traceView condition
hi-ogawa 82c10cd
nit
hi-ogawa ee4af34
wip: add vitest:onAfterRetryTask
hi-ogawa 5261be2
todo
hi-ogawa f41d703
test: update snap
hi-ogawa 1d188f6
todo
hi-ogawa 811f7ec
docs: deslop
hi-ogawa 21565b1
docs(browser): clarify browser runner shared state
hi-ogawa c1cad46
refactor(browser): store trace runtime on browser state
hi-ogawa 8533e97
deslop
hi-ogawa fc6957e
test: wip e2e
hi-ogawa f93229e
test: e2e html reporter
hi-ogawa 072c0f4
test: basic e2e
hi-ogawa 54363ac
test: dig deeper
hi-ogawa 5f101c5
Merge branch 'main' into wip-builtin-trace-system
hi-ogawa f82c207
test: test trace artifact recording
hi-ogawa 1599e84
resolve todo
hi-ogawa a40a451
fix: fix retry/repeats counter
hi-ogawa 34f50c7
fix: tweak retry/repeat combination label
hi-ogawa 52aa365
Revert "wip: SerializedRootConfig"
hi-ogawa 2a4f9ba
Revert "fix/refactor: pass serializeRootConfig to UI"
hi-ogawa 5529764
Merge branch 'main' into wip-builtin-trace-system
hi-ogawa 05f3f83
test: cleanup
hi-ogawa 9f92842
test: update wdio
hi-ogawa 3e4bd08
chore: revert auto config
hi-ogawa b9824f6
test(browser): expand trace fidelity fixtures
hi-ogawa 58fd527
chore: comment
hi-ogawa bf3ced0
todo
hi-ogawa 2fa7b14
feat(browser): preserve trace viewport and scroll
hi-ogawa 5dca079
feat(browser): expose trace view fidelity options
hi-ogawa e8f8932
docs(browser): document trace view fidelity options
hi-ogawa af901e0
docs(browser): clarify trace view resource limits
hi-ogawa cf75cc0
feat(browser): add trace view status metadata
hi-ogawa 36997e9
feat(browser): add trace view timing
hi-ogawa b822426
chore(browser): format trace action names
hi-ogawa 9147e78
chore(browser): move browser timing helper
hi-ogawa 1570b54
fix(browser): add trace lifecycle location fallback
hi-ogawa 03d8d55
resolve todo
hi-ogawa 8a3c0c7
feat(ui): make trace view panes resizable
hi-ogawa afadd8e
refactor(browser): use trace attempts as active state
hi-ogawa fac078a
chore: tweak split pane
hi-ogawa 86ead20
docs(browser): update trace view behavior notes
hi-ogawa 209dc3d
fix(ui): isolate trace replay background
hi-ogawa d17c1ee
fix(ui): refine trace replay pane fallback
hi-ogawa 50e6be9
docs(browser): update trace view screenshots
hi-ogawa 97ae085
docs(browser): credit trace view screenshot component
hi-ogawa a35c8d4
fix(browser): avoid stale trace lifecycle stack
hi-ogawa f354f56
comment
hi-ogawa 335991a
deslop
hi-ogawa e01de4f
refactor(ui): simplify trace view state
hi-ogawa 84fd25e
refactor(ui): share trace attempt label
hi-ogawa 0d3e913
deslop
hi-ogawa 943eaf2
deslop
hi-ogawa faba504
is this vue?
hi-ogawa 44393de
docs(browser): promote built-in trace view guide
hi-ogawa e518880
docs: tweak
hi-ogawa 11c191e
cleanup
hi-ogawa b9a15c0
test: demo hover on replay interaction time
hi-ogawa 44bac4d
wip: snapshot hover and focus
hi-ogawa 7ec898e
fix: patch for :focus replay
hi-ogawa fab84de
fix: support :fucus-within
hi-ogawa 148850b
chore: lint
hi-ogawa 657bc0f
chore: just patch esm
hi-ogawa 4da7d3a
test: test stylesheet
hi-ogawa 454c7be
fix: auto reload active trace view on re-run
hi-ogawa b8ff16a
Merge branch 'main' into wip-builtin-trace-system
hi-ogawa 15d6b22
test: e2e trace viewport and pseudo states
hi-ogawa 7e66ae2
test: e2e css-link and image
hi-ogawa e6976a0
test: e2e window scroll
hi-ogawa ddb5c95
resolve todo
hi-ogawa 4bf707d
test: restore file
hi-ogawa 6f4394b
test: update snap
hi-ogawa 6a78968
test: update trace explorer item helper
hi-ogawa 55bf6ed
tweak ui
hi-ogawa 35f9987
tweak ui
hi-ogawa 0c11f7f
docs: cleanup
hi-ogawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| title: browser.traceView | Config | ||
| outline: deep | ||
| --- | ||
|
|
||
| # browser.traceView <Badge type="warning" text="Experimental" /> <Version>5.0.0</Version> | ||
|
|
||
| - **Type:** `boolean | { enabled?: boolean; recordCanvas?: boolean; inlineImages?: boolean }` | ||
| - **CLI:** `--browser.traceView` | ||
| - **Default:** `false` | ||
|
|
||
| Enable 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. | ||
|
|
||
| ```ts | ||
| export default defineConfig({ | ||
| test: { | ||
| browser: { | ||
| traceView: true, | ||
| }, | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| Use the object form to enable additional snapshot fidelity options: | ||
|
|
||
| ```ts | ||
| export default defineConfig({ | ||
| test: { | ||
| browser: { | ||
| traceView: { | ||
| enabled: true, | ||
| inlineImages: true, | ||
| recordCanvas: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| | Option | Default | Description | | ||
| | --- | --- | --- | | ||
| | `enabled` | `false` | Enables Vitest trace-view artifact collection. | | ||
| | `inlineImages` | `false` | Inlines loaded `<img>` pixels into snapshots for more portable replay, useful in the HTML reporter. | | ||
| | `recordCanvas` | `false` | Captures canvas pixels in snapshots. | | ||
|
|
||
| ## browser.traceView.enabled {#traceview-enabled} | ||
|
|
||
| - **Type:** `boolean` | ||
| - **Default:** `false` | ||
| - **CLI:** `--browser.traceView.enabled` | ||
|
|
||
| Enables Vitest trace-view artifact collection. | ||
|
|
||
| ## browser.traceView.inlineImages {#traceview-inlineimages} | ||
|
|
||
| - **Type:** `boolean` | ||
| - **Default:** `false` | ||
| - **CLI:** `--browser.traceView.inlineImages` | ||
|
|
||
| Inlines loaded `<img>` pixels into snapshots for more portable replay, useful in the HTML reporter. | ||
|
|
||
| ## browser.traceView.recordCanvas {#traceview-recordcanvas} | ||
|
|
||
| - **Type:** `boolean` | ||
| - **Default:** `false` | ||
| - **CLI:** `--browser.traceView.recordCanvas` | ||
|
|
||
| Captures canvas pixels in snapshots. This enables a weaker replay iframe sandbox because rrweb needs scripts to redraw canvas data. | ||
|
|
||
| See [Trace View](/guide/browser/trace-view) for full documentation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # Playwright Traces | ||
|
|
||
| Vitest Browser Mode supports generating Playwright's [trace files](https://playwright.dev/docs/trace-viewer#viewing-remote-traces). To enable tracing, you need to set the [`trace`](/config/browser/trace) option in the `test.browser` configuration. | ||
|
|
||
| ::: warning | ||
| Generating trace files is only available when using the [Playwright provider](/config/browser/playwright). | ||
| ::: | ||
|
|
||
| ::: code-group | ||
| ```ts [vitest.config.js] | ||
| import { defineConfig } from 'vitest/config' | ||
| import { playwright } from '@vitest/browser-playwright' | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| browser: { | ||
| provider: playwright(), | ||
| trace: 'on', | ||
| }, | ||
| }, | ||
| }) | ||
| ``` | ||
| ```bash [CLI] | ||
| vitest --browser.trace=on | ||
| ``` | ||
| ::: | ||
|
|
||
| By default, Vitest will generate a trace file for each test. You can also configure it to only generate traces on test failures by setting `trace` to `'on-first-retry'`, `'on-all-retries'` or `'retain-on-failure'`. The files will be saved in `__traces__` folder next to your test files. The name of the trace includes the project name, the test name, the [`repeats`](/api/test#repeats) count and [`retry`](/api/test#retry) count: | ||
|
|
||
| ``` | ||
| chromium-my-test-0-0.trace.zip | ||
| ^^^^^^^^ project name | ||
| ^^^^^^ test name | ||
| ^ repeat count | ||
| ^ retry count | ||
| ``` | ||
|
|
||
| To change the output directory, you can set the `tracesDir` option in the `test.browser.trace` configuration. This way all traces will be stored in the same directory, grouped by the test file. | ||
|
|
||
| ```ts [vitest.config.js] | ||
| import { defineConfig } from 'vitest/config' | ||
| import { playwright } from '@vitest/browser-playwright' | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| browser: { | ||
| provider: playwright(), | ||
| trace: { | ||
| mode: 'on', | ||
| // the path is relative to the root of the project | ||
| tracesDir: './playwright-traces', | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| The traces are available in reporters as [annotations](/guide/test-annotations). For example, in the HTML reporter, you can find the link to the trace file in the test details. | ||
|
|
||
| ## Trace markers | ||
|
|
||
| You can add explicit named markers to make the trace timeline easier to read: | ||
|
|
||
| ```ts | ||
| import { page } from 'vitest/browser' | ||
|
|
||
| document.body.innerHTML = ` | ||
| <button type="button">Sign in</button> | ||
| ` | ||
|
|
||
| await page.getByRole('button', { name: 'Sign in' }).mark('sign in button rendered') | ||
| ``` | ||
|
|
||
| Both `page.mark(name)` and `locator.mark(name)` are available. | ||
|
|
||
| You can also group multiple operations under one marker with `page.mark(name, callback)`: | ||
|
|
||
| ```ts | ||
| await page.mark('sign in flow', async () => { | ||
| await page.getByRole('textbox', { name: 'Email' }).fill('john@example.com') | ||
| await page.getByRole('textbox', { name: 'Password' }).fill('secret') | ||
| await page.getByRole('button', { name: 'Sign in' }).click() | ||
| }) | ||
| ``` | ||
|
|
||
| You can also wrap reusable helpers with [`vi.defineHelper()`](/api/vi#vi-defineHelper) so trace entries point to where the helper is called, not its internals: | ||
|
|
||
| ```ts | ||
| import { vi } from 'vitest' | ||
| import { page } from 'vitest/browser' | ||
|
|
||
| const myRender = vi.defineHelper(async (content: string) => { | ||
| document.body.innerHTML = content | ||
| await page.elementLocator(document.body).mark('render helper') | ||
| }) | ||
|
|
||
| test('renders content', async () => { | ||
| await myRender('<button>Hello</button>') // trace points to this line | ||
| }) | ||
| ``` | ||
|
|
||
| ## Preview | ||
|
|
||
| To open the trace file, you can use the Playwright Trace Viewer. Run the following command in your terminal: | ||
|
|
||
| ```bash | ||
| npx playwright show-trace "path-to-trace-file" | ||
| ``` | ||
|
|
||
| This will start the Trace Viewer and load the specified trace file. | ||
|
|
||
| Alternatively, you can open the Trace Viewer in your browser at https://trace.playwright.dev and upload the trace file there. | ||
|
|
||
| <img alt="Trace Viewer showing the trace timeline and rendered component" img-light src="/trace-viewer-light.png"> | ||
| <img alt="Trace Viewer showing the trace timeline and rendered component" img-dark src="/trace-viewer-dark.png"> | ||
|
|
||
| ## Source Location | ||
|
|
||
| When you open a trace, you'll notice that Vitest groups browser interactions and links them back to the exact line in your test that triggered them. This happens automatically for: | ||
|
|
||
| - `expect.element(...)` assertions | ||
| - Interactive actions like `click`, `fill`, `type`, `hover`, `selectOptions`, `upload`, `dragAndDrop`, `tab`, `keyboard`, `wheel`, and screenshots | ||
|
|
||
| Under the hood, Playwright still records its own low-level action events as usual. Vitest wraps them with source-location groups so you can jump straight from the trace timeline to the relevant line in your test. | ||
|
|
||
| For anything not covered automatically, you can use `page.mark()` or `locator.mark()` to add your own trace groups — see [Trace markers](#trace-markers) above. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New trace view took over the page, so I rename the playwright trace. Not sure if we should keep the sidebar though.