vitest-dev / vitest-dev/vitest
Browser traces as task artifacts
Nobody has claimed this yet.
- 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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