Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Bug]: Tests whose titles differ only in punctuation share one output directory, and the later test deletes the earlier test's artifacts

Aperta
#43,347 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@alok-108 ci sta già lavorando.

Dal 15/10/2026.

  • #43401 di @alok-108 — chiusa senza merge

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

P3-collecting-feedback
Version

1.64.0

Steps to reproduce
  1. Clone https://github.com/dennev/playwright-output-dir-collision (no browser needed)
  2. npm install
  3. npx playwright test
  4. 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.ts and workerMain.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.ts and a-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.
  • TestInfoImpl makes the directory name from sanitizeForFilePath() of the title path, plus the project, retry and repeat suffixes. workerMain.ts calls removeFolders([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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/playwright

Tutte le issue di microsoft/playwright

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.