Skip to content

fix(test-runner): use describe name in output dir #8282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/test/workerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ export class WorkerRunner extends EventEmitter {
const baseOutputDir = (() => {
const relativeTestFilePath = path.relative(this._project.config.testDir, test._requireFile.replace(/\.(spec|test)\.(js|ts|mjs)$/, ''));
const sanitizedRelativePath = relativeTestFilePath.replace(process.platform === 'win32' ? new RegExp('\\\\', 'g') : new RegExp('/', 'g'), '-');
let testOutputDir = sanitizedRelativePath + '-' + sanitizeForFilePath(test.title);
const fullTitleWithoutSpec = test.titlePath().slice(1).join(' ');
let testOutputDir = sanitizedRelativePath + '-' + sanitizeForFilePath(fullTitleWithoutSpec);
if (this._uniqueProjectNamePathSegment)
testOutputDir += '-' + this._uniqueProjectNamePathSegment;
if (retry)
Expand Down
18 changes: 9 additions & 9 deletions tests/playwright-test/playwright.artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ test('should work with screenshot: on', async ({ runInlineTest }, testInfo) => {
' test-failed-1.png',
'artifacts-persistent-passing',
' test-finished-1.png',
'artifacts-shared-failing',
'artifacts-shared-shared-failing',
' test-failed-1.png',
'artifacts-shared-passing',
'artifacts-shared-shared-passing',
' test-finished-1.png',
'artifacts-two-contexts',
' test-finished-1.png',
Expand Down Expand Up @@ -177,7 +177,7 @@ test('should work with screenshot: only-on-failure', async ({ runInlineTest }, t
' test-failed-1.png',
'artifacts-persistent-failing',
' test-failed-1.png',
'artifacts-shared-failing',
'artifacts-shared-shared-failing',
' test-failed-1.png',
'artifacts-two-contexts-failing',
' test-failed-1.png',
Expand Down Expand Up @@ -210,9 +210,9 @@ test('should work with trace: on', async ({ runInlineTest }, testInfo) => {
' trace.zip',
'artifacts-persistent-passing',
' trace.zip',
'artifacts-shared-failing',
'artifacts-shared-shared-failing',
' trace.zip',
'artifacts-shared-passing',
'artifacts-shared-shared-passing',
' trace.zip',
'artifacts-two-contexts',
' trace-1.zip',
Expand Down Expand Up @@ -242,7 +242,7 @@ test('should work with trace: retain-on-failure', async ({ runInlineTest }, test
' trace.zip',
'artifacts-persistent-failing',
' trace.zip',
'artifacts-shared-failing',
'artifacts-shared-shared-failing',
' trace.zip',
'artifacts-two-contexts-failing',
' trace-1.zip',
Expand All @@ -269,7 +269,7 @@ test('should work with trace: on-first-retry', async ({ runInlineTest }, testInf
' trace.zip',
'artifacts-persistent-failing-retry1',
' trace.zip',
'artifacts-shared-failing-retry1',
'artifacts-shared-shared-failing-retry1',
' trace.zip',
'artifacts-two-contexts-failing-retry1',
' trace-1.zip',
Expand Down Expand Up @@ -312,9 +312,9 @@ test('should stop tracing with trace: on-first-retry, when not retrying', async
expect(result.passed).toBe(1);
expect(result.flaky).toBe(1);
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'a-flaky-retry1',
'a-shared-flaky-retry1',
' trace.zip',
'a-no-tracing', // Empty dir created because of testInfo.outputPath() call.
'a-shared-no-tracing', // Empty dir created because of testInfo.outputPath() call.
'report.json',
]);
});
15 changes: 15 additions & 0 deletions tests/playwright-test/test-output-dir.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,18 @@ test('should allow nonAscii characters in the output dir', async ({ runInlineTes
const outputDir = result.output.split('\n').filter(x => x.startsWith('%%'))[0].slice('%%'.length);
expect(outputDir).toBe(path.join(testInfo.outputDir, 'test-results', 'my-test-こんにちは世界'));
});

test('should allow include the describe name the output dir', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'my-test.spec.js': `
const { test } = pwt;
test.describe('hello', () => {
test('world', async ({}, testInfo) => {
console.log('\\n%%' + testInfo.outputDir);
});
});
`,
});
const outputDir = result.output.split('\n').filter(x => x.startsWith('%%'))[0].slice('%%'.length);
expect(outputDir).toBe(path.join(testInfo.outputDir, 'test-results', 'my-test-hello-world'));
});