vitest-dev / vitest-dev/vitest

Browser traces as task artifacts

Open
#10,177 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement: pending triage
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 21h
Merged PRs (30d)
92

Description

Clear and concise description of the problem

Currently it is pretty hacky to get the traces path for a reporter. Example in alternative bellow.

Suggested solution

Implement the experimental artifact attachments as made here https://github.com/vitest-dev/vitest/blob/72a6dc25794cd8400dc10054db5a76df6da0bdaa/packages/browser/src/client/tester/runner.ts#L177-L180

The traces are manage here https://github.com/vitest-dev/vitest/blob/72a6dc25794cd8400dc10054db5a76df6da0bdaa/packages/browser/src/client/tester/runner.ts#L128-L145

Alternative

A custom hacky manual way breakable to any internal changes of vitest.

import { getTestName } from '@vitest/runner/utils';
import { server } from 'vitest/browser';
import * as allure from 'allure-js-commons';

// Link the trace to allure (mostly based on internal sources of vitest cause functions not exposed neither the trace be added in artifacts)
const sanitize = (str: string): string => str.replaceAll(/[^a-z0-9]/gi, '-');
async (): Promise<void> => {
  const { retryCount = 0, repeatCount = 0 } = task.result ?? {};
  const testPath = task.file.filepath;

  const path = testPath.split('/');
  const fileName = path.pop();
  const tracePath = [
    ...path,
    '__traces__',
    fileName,
    `${sanitize(task.file.projectName ?? '')}-${sanitize(getTestName(task, '-'))}-${repeatCount}-${retryCount}.trace.zip`,
  ].join('/');

  if (server.commands.hostFileExists(tracePath)) {
    console.info('Attaching', `${prefix}Trace.zip`, tracePath);
    await allure.attachmentPath(`${prefix}Trace.zip`, tracePath, 'application/zip');
  } else {
    console.log('No file for trace', tracePath);
  }
}
Additional context

No response

Validations

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 in packages/browser/src/client/tester/runner.ts, comparing the trace-management section around lines 128-145 with the experimental artifact-attachment code around lines 177-180. Follow the existing browser test and reporter flow to expose traces as task artifacts, and verify that reporters can consume the attachments without reconstructing internal trace paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.