Browser Mode: tests with the same name in different files fail with "tracing.stopChunk: file data stream has unexpected number of bytes"
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- playwright, typescript
- Domain
- testing-qa
Research direction
Start in packages/browser/src/client/tester/runner.ts and read getTraceName, then check how the trace chunk name is used when parallel tests record traces. The report proposes adding the test id and limiting the sanitized title length; compare that approach with the failure screenshot naming issue and #11880. Done when same-named tests in different files get distinct trace files and long names stay within filesystem limits.
Written by the indexing model from the issue text.
Description
Describe the bug
With browser.trace set to retain-on-failure (or any mode that records), a passing test is reported as failed with:
FAIL |chromium| src/components/Foo.stories.tsx > Default
Error: tracing.stopChunk: file data stream has unexpected number of bytes
It happens when tests with the same name in different test files run at the same time.
Storybook portable stories trigger it often, because Default and base are the usual story names.
getTraceName (packages/browser/src/client/tester/runner.ts) builds the chunk name only from the test name, the repeat count and the retry count.
The name does not include anything that identifies the test file or the test.
Playwright writes the files of a trace chunk under that name in a directory shared by all the browser contexts of the browser.
When two contexts record a chunk with the same name at once, they write the same files, and stopChunk fails when it zips them.
The failing test is the one that stops its chunk second, and it is reported as failed even though its assertions passed.
Evidence that the name is the cause:
- We see it intermittently in CI and locally in Storybook test runs that run several story files in one browser (Vitest 5.1.0,
@vitest/browser-playwright5.1.0, Chromium).
In the two logs we inspected, the failed tests were stories namedDefault,playgroundandbase, and a story with the same name ran in another file of the same run. - pdevito3/FullstackTemplate#378 describes the same error for two same-named tests in two files, failing in 9 of 10 runs, and passing in 10 of 10 when the titles differ.
pdevito3/FullstackTemplate#375 reports the same error in CI.
The related #11880 reports that the same name is also too long when the test name is long (ENAMETOOLONG).
Suggested fix
Make the chunk name unique per test and bounded in length: cut the sanitized title and add the test id.
function getTraceName(task: Task, retryCount: number, repeatsCount: number) {
const title = getTestName(task, '-').replace(/[^a-z0-9]/gi, '-').slice(0, 100)
return `${title}-${task.id.replace(/[^a-z0-9]/gi, '-')}-${repeatsCount}-${retryCount}`
}
The test id is a hash of the file path and project name plus the position of the test, so it is the same on every run.
A test that fails again overwrites its own trace file, and tests with the same title in different files no longer share one.
This also fixes the ENAMETOOLONG case from #11880 for traces.
Failure screenshots use getFailureScreenshotName, which has the same length problem.
We run this change as a patch and will open a PR if this direction is fine.
Reproduction
Two test files that each contain a test with the same name, run in one browser with browser.trace: 'retain-on-failure' and file parallelism on.
I do not have a standalone repository yet.
The linked FullstackTemplate issues describe one.
System Info
vitest: 5.1.0
@vitest/browser-playwright: 5.1.0
playwright: 1.56.1 (Chromium, headless)
Node: 22.20.0
OS: Linux (remote build workers)
Used Package Manager
pnpm
- Dominant language
- TypeScript
- Stars
- 17.4k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 148
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from vitest-dev/vitest
-
approved documentation
Difficulty 1/5 Under an hour Newbie friendliness 89/100
vitest-dev/vitest#12015 · 4 comments ·
Maintainers usually reply within 1 day
-
docs: say that `vi.stubEnv` changes only `import.meta.env` in Browser ModeMay be free again A pull request for this issue was closed without being merged. Opendocumentation p1-chore
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
vitest-dev/vitest#11971 ·
Maintainers usually reply within 1 day
-
A fixture named `task` breaks `expect` from the test contextMay be free again @hrishikeshpathak1009 claimed this 7 days ago, and no pull request is open. Openp2-edge-case
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vitest-dev/vitest#11929 · 1 comment ·
Maintainers usually reply within 1 day
-
`%%` in a `test.each` / `describe.each` / `test.for` title consumes a parameterMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vitest-dev/vitest#11913 · 1 comment ·
Maintainers usually reply within 1 day
-
Docs: importOriginal return type is missing PromisePossibly taken @ragib-mrb claimed this 6 days ago. Opendocumentation
Difficulty 1/5 Under an hour Newbie friendliness 94/100
vitest-dev/vitest#11894 · 1 comment ·
Maintainers usually reply within 1 day
All issues in vitest-dev/vitest
Similar issues
-
approved check:passed streams:remove
Difficulty 1/5 Under an hour Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Monthly Not a priority
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Expensify/App#107229 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
GitTools/actions#2297 · 1 reaction ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
hiero-ledger/hiero-sdk-js#4793 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
microsoft/vscode-cosmosdb#3594 · 1 comment ·
Maintainers usually reply within 1 day