Skip to content

Commit a8a3799

Browse files
fix(test-runner): use describe name in output dir (#8282)
1 parent a48dd8b commit a8a3799

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/test/workerRunner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ export class WorkerRunner extends EventEmitter {
202202
const baseOutputDir = (() => {
203203
const relativeTestFilePath = path.relative(this._project.config.testDir, test._requireFile.replace(/\.(spec|test)\.(js|ts|mjs)$/, ''));
204204
const sanitizedRelativePath = relativeTestFilePath.replace(process.platform === 'win32' ? new RegExp('\\\\', 'g') : new RegExp('/', 'g'), '-');
205-
let testOutputDir = sanitizedRelativePath + '-' + sanitizeForFilePath(test.title);
205+
const fullTitleWithoutSpec = test.titlePath().slice(1).join(' ');
206+
let testOutputDir = sanitizedRelativePath + '-' + sanitizeForFilePath(fullTitleWithoutSpec);
206207
if (this._uniqueProjectNamePathSegment)
207208
testOutputDir += '-' + this._uniqueProjectNamePathSegment;
208209
if (retry)

tests/playwright-test/playwright.artifacts.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ test('should work with screenshot: on', async ({ runInlineTest }, testInfo) => {
145145
' test-failed-1.png',
146146
'artifacts-persistent-passing',
147147
' test-finished-1.png',
148-
'artifacts-shared-failing',
148+
'artifacts-shared-shared-failing',
149149
' test-failed-1.png',
150-
'artifacts-shared-passing',
150+
'artifacts-shared-shared-passing',
151151
' test-finished-1.png',
152152
'artifacts-two-contexts',
153153
' test-finished-1.png',
@@ -177,7 +177,7 @@ test('should work with screenshot: only-on-failure', async ({ runInlineTest }, t
177177
' test-failed-1.png',
178178
'artifacts-persistent-failing',
179179
' test-failed-1.png',
180-
'artifacts-shared-failing',
180+
'artifacts-shared-shared-failing',
181181
' test-failed-1.png',
182182
'artifacts-two-contexts-failing',
183183
' test-failed-1.png',
@@ -210,9 +210,9 @@ test('should work with trace: on', async ({ runInlineTest }, testInfo) => {
210210
' trace.zip',
211211
'artifacts-persistent-passing',
212212
' trace.zip',
213-
'artifacts-shared-failing',
213+
'artifacts-shared-shared-failing',
214214
' trace.zip',
215-
'artifacts-shared-passing',
215+
'artifacts-shared-shared-passing',
216216
' trace.zip',
217217
'artifacts-two-contexts',
218218
' trace-1.zip',
@@ -242,7 +242,7 @@ test('should work with trace: retain-on-failure', async ({ runInlineTest }, test
242242
' trace.zip',
243243
'artifacts-persistent-failing',
244244
' trace.zip',
245-
'artifacts-shared-failing',
245+
'artifacts-shared-shared-failing',
246246
' trace.zip',
247247
'artifacts-two-contexts-failing',
248248
' trace-1.zip',
@@ -269,7 +269,7 @@ test('should work with trace: on-first-retry', async ({ runInlineTest }, testInf
269269
' trace.zip',
270270
'artifacts-persistent-failing-retry1',
271271
' trace.zip',
272-
'artifacts-shared-failing-retry1',
272+
'artifacts-shared-shared-failing-retry1',
273273
' trace.zip',
274274
'artifacts-two-contexts-failing-retry1',
275275
' trace-1.zip',
@@ -312,9 +312,9 @@ test('should stop tracing with trace: on-first-retry, when not retrying', async
312312
expect(result.passed).toBe(1);
313313
expect(result.flaky).toBe(1);
314314
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
315-
'a-flaky-retry1',
315+
'a-shared-flaky-retry1',
316316
' trace.zip',
317-
'a-no-tracing', // Empty dir created because of testInfo.outputPath() call.
317+
'a-shared-no-tracing', // Empty dir created because of testInfo.outputPath() call.
318318
'report.json',
319319
]);
320320
});

tests/playwright-test/test-output-dir.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,18 @@ test('should allow nonAscii characters in the output dir', async ({ runInlineTes
270270
const outputDir = result.output.split('\n').filter(x => x.startsWith('%%'))[0].slice('%%'.length);
271271
expect(outputDir).toBe(path.join(testInfo.outputDir, 'test-results', 'my-test-こんにちは世界'));
272272
});
273+
274+
test('should allow include the describe name the output dir', async ({ runInlineTest }, testInfo) => {
275+
const result = await runInlineTest({
276+
'my-test.spec.js': `
277+
const { test } = pwt;
278+
test.describe('hello', () => {
279+
test('world', async ({}, testInfo) => {
280+
console.log('\\n%%' + testInfo.outputDir);
281+
});
282+
});
283+
`,
284+
});
285+
const outputDir = result.output.split('\n').filter(x => x.startsWith('%%'))[0].slice('%%'.length);
286+
expect(outputDir).toBe(path.join(testInfo.outputDir, 'test-results', 'my-test-hello-world'));
287+
});

0 commit comments

Comments
 (0)