[Bug]: Tests whose titles differ only in punctuation share one output directory, and the later test deletes the earlier test's artifacts
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 28/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- testing
Direzione di ricerca
Start with the reproduction in tests/collision.spec.ts: two titles that differ only in punctuation map to the same outputDir. The directory name comes from sanitizeForFilePath() in TestInfoImpl (testInfo.ts), and workerMain.ts calls removeFolders on that directory before each test. Done means both tests get distinct directories, the failing test keeps evidence.txt and error-context.md, and snapshot paths stay unchanged. The reporter's proposed fix, and the earlier attempts #23414, #24213 and #24465, are in the thread, so check them before you start.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Version
1.64.0
Steps to reproduce
- Clone https://github.com/dennev/playwright-output-dir-collision (no browser needed)
npm installnpx playwright test- Look at
test-results/.
tests/collision.spec.ts:
import fs from 'node:fs';
import { test, expect } from '@playwright/test';
test('offset (x +1)', async ({}, testInfo) => {
fs.writeFileSync(testInfo.outputPath('evidence.txt'), 'written by the failing test');
console.log('first test outputDir:', testInfo.outputDir);
expect(1).toBe(2);
});
test('offset (x 1)', async ({}, testInfo) => {
console.log('second test outputDir:', testInfo.outputDir);
});
playwright.config.ts: defineConfig({ testDir: './tests', workers: 1, reporter: 'list' })
Expected behavior
Each test gets its own output directory, so the failing test keeps evidence.txt and error-context.md, as it does when the second test is removed. The documentation of testInfo.outputDir says: "Each test run gets its own directory so they cannot conflict."
Actual behavior
Both tests print the same outputDir, which ends in test-results/collision-offset-x-1-. Playwright deletes that directory before the second test runs. After the run, test-results/ contains only .last-run.json: the failing test's evidence.txt and its error-context.md are gone, although the list reporter still prints Error Context: test-results/collision-offset-x-1-/error-context.md.
With fullyParallel: true and more than one worker, the two tests can also run at the same time in the same directory.
Additional context
- This is the problem of #23386. #23414 changed
sanitizeForFilePath()to add a hash whenever it replaced anything other than a single space. That function also names snapshot files, so existing snapshot names changed (#24184), and #24213 reverted it. A second attempt, #24465, kept snapshot names but still added a hash to the output directory of every test whose title has such characters. It was not merged, and #23386 was closed with the comment that fixing it would break existing users. - The fix I propose changes far fewer names. It does not change
sanitizeForFilePath(). It changes a directory name only when two or more tests in the same file get that name, and today such a directory keeps only the artifacts of the test that ran last. All other output directory names stay the same, byte for byte, and snapshot paths do not change. One side effect: when you add or remove a test, another test in the same file can get a new directory name, if their names collide. - I have this fix with a test on a branch. It changes
testInfo.tsandworkerMain.ts: the worker finds the names that two or more tests of the loaded file get, and adds the first 8 hex digits of a SHA-1 of the title path to them. The result does not depend on run order, the number of workers or--grep. I can open a pull request if you approve this for a community contribution. - Not covered: tests in different files that get the same name (for example
a/b.spec.tsanda-b.spec.ts), because a worker loads only one file; and names that differ only in letter case, which are one directory on Windows and macOS. I can include letter case if you want it, but then those names would also change on Linux. TestInfoImplmakes the directory name fromsanitizeForFilePath()of the title path, plus the project, retry and repeat suffixes.workerMain.tscallsremoveFolders([testInfo.outputDir])before each test. The duplicate-title check does not find this, because the titles are different.- Reproduced on Linux (environment below) and on Windows 11 with Node 26.10.0.
- I found this when a failing test lost its screenshot and error context to a passing test whose title differed only by a
+. My workaround is a check that lists the tests and rejects titles that give the same directory name.
Environment
System:
OS: Linux 6.18 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12400F
Memory: 20.63 GB / 23.37 GB
Container: Yes
Binaries:
Node: 24.21.0 - /usr/local/bin/node
Yarn: 1.22.22 - /usr/local/bin/yarn
npm: 11.19.0 - /usr/local/bin/npm
Languages:
Bash: 5.2.15 - /usr/bin/bash
npmPackages:
@playwright/test: 1.64.0 => 1.64.0
- Lingua principale
- TypeScript
- Stelle
- 98k
- Fork
- 6.6k
- Merge medio
- 16h 20m
- PR unite (30g)
- 301
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/playwright
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
microsoft/playwright#43581 · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
[Feature]: Set `this.name` in `TargetClosedError` constructorForse di nuovo libera @LeonxLJX l’ha presa 48 giorni fa e non c’è nessuna pull request aperta. ApertaP3-collecting-feedback
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
microsoft/playwright#42522 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
microsoft/playwright#43586 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
microsoft/playwright#43587 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 1-2 giorni Idoneità per principianti 55/100
microsoft/playwright#43588 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/playwright
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
Automattic/data-liberation-agent#953 ·
I maintainer di solito rispondono entro 1 giorno
-
README に GitHub の組織のバッジを足すApertadocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
funmary-app/funmary#399 ·
I maintainer di solito rispondono entro 1 giorno
-
area:curator enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
CassioDalla/Scrinalia#150 ·
I maintainer di solito rispondono entro 1 giorno
-
status: needs-triage v1-bug-bash
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
a2ui-project/a2ui#3533 ·
I maintainer di solito rispondono entro 1 giorno
-
backend enhancement priority:P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
geolens-io/geolens#3310 ·
I maintainer di solito rispondono entro 1 giorno