vitest-dev / vitest-dev/vitest

Support Trace View outside browser mode

Open
#11,045 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Motivation

Vitest's Trace View provides useful step-by-step DOM snapshots, but trace collection is currently coupled to browser mode. Some users run E2E tests in Vitest's Node environment and control a complete app or page through a programmatic API such as Playwright. This is a different use case from running test code in the browser-mode runtime, but both can benefit from inspecting recorded test flows in the Vitest UI and HTML report.

As agents increasingly help author and run tests, a human reviewer may want to quickly skim the recorded states in a generated HTML report and judge whether the UI and interactions look right, whether iterating locally or reviewing a CI run.

Proposed Approach / Hypothetical API

Expose the existing snapshot producer as an injectable client script and provide a task-side helper that records its opaque result as a Trace View entry. The caller owns script injection, browser lifecycle, and the transfer from the page back to the test.

For example, an integration using the Playwright programmatic API could look roughly like this:

import {
  recordTraceViewSnapshot,
  traceViewClientPath,
} from 'vitest/trace-view'

test('checkout', async (context) => {
  await page.addInitScript({ path: traceViewClientPath })

  await page.goto(appUrl)

  const snapshot = await page.evaluate(() => {
    return globalThis.__vitest_trace_view__.snapshot()
  })

  await recordTraceViewSnapshot(context.task, {
    name: 'checkout page',
    snapshot,
  })
})

The snapshot value remains opaque. recordTraceViewSnapshot owns the internal artifact envelope, attempt metadata, and defaults expected by the viewer. The Vitest UI and HTML reporter discover the resulting trace from artifact presence rather than browser-mode configuration.

Browser mode remains the built-in higher-level integration that automatically records actions, assertions, marks, retries, and final state. Playwright fixtures, automatic lifecycle capture, and locator assertions can be explored separately as ergonomics on top of the same primitive.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked design note and the existing snapshot producer behind browser-mode Trace View. Trace how the UI and HTML reporter discover trace artifacts, then assess the proposed injectable client script and task-side helper. Done means Node-environment callers can record an opaque snapshot that appears in both viewers with the expected envelope and metadata.

Written by the indexing model from the issue text.

Assessment

Tech stack
playwright, typescript
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.