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

This commit is contained in:
Joel Einbinder 2021-08-24 10:33:40 -04:00 committed by GitHub
parent a48dd8b84b
commit a8a3799e9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 10 deletions

View File

@ -202,7 +202,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)

View File

@ -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',
@ -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',
@ -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',
@ -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',
@ -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',
@ -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',
]);
});

View File

@ -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'));
});