feat(ui): merge stdio in html report (#9560)

This commit is contained in:
Pavel Feldman 2021-10-15 15:15:06 -08:00 committed by GitHub
parent 01c702adbb
commit 9135847950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 4 deletions

View file

@ -255,7 +255,7 @@ export const AttachmentLink: React.FunctionComponent<{
{attachment.path && <a href={href || attachment.path} target='_blank'>{attachment.name}</a>} {attachment.path && <a href={href || attachment.path} target='_blank'>{attachment.name}</a>}
{attachment.body && <span>{attachment.name}</span>} {attachment.body && <span>{attachment.name}</span>}
</div>} loadChildren={attachment.body ? () => { </div>} loadChildren={attachment.body ? () => {
return [<div className='attachment-body'>${attachment.body}</div>]; return [<div className='attachment-body'>{attachment.body}</div>];
} : undefined} depth={0}></TreeItem>; } : undefined} depth={0}></TreeItem>;
}; };

View file

@ -233,7 +233,7 @@ class HtmlBuilder {
testId: test.testId, testId: test.testId,
title: test.title, title: test.title,
location: this._relativeLocation(test.location), location: this._relativeLocation(test.location),
results: test.results.map(r => this._createTestResult(test, r)) results: test.results.map(r => this._createTestResult(r))
}; };
} }
@ -278,7 +278,8 @@ class HtmlBuilder {
}; };
} }
private _createTestResult(test: JsonTestCase, result: JsonTestResult): TestResult { private _createTestResult(result: JsonTestResult): TestResult {
let lastAttachment: TestAttachment | undefined;
return { return {
duration: result.duration, duration: result.duration,
startTime: result.startTime, startTime: result.startTime,
@ -303,8 +304,18 @@ class HtmlBuilder {
body: a.body, body: a.body,
}; };
} }
if ((a.name === 'stdout' || a.name === 'stderr') &&
a.contentType === 'text/plain' &&
lastAttachment &&
lastAttachment.name === a.name &&
lastAttachment.contentType === a.contentType) {
lastAttachment.body += a.body as string;
return null;
}
lastAttachment = a;
return a; return a;
}) }).filter(Boolean) as TestAttachment[]
}; };
} }

View file

@ -228,3 +228,27 @@ test('should include screenshot on failure', async ({ runInlineTest, page, showR
const src = await page.locator('img').getAttribute('src'); const src = await page.locator('img').getAttribute('src');
expect(src).toBeTruthy(); expect(src).toBeTruthy();
}); });
test('should include stdio', async ({ runInlineTest, page, showReport }) => {
const result = await runInlineTest({
'a.test.js': `
const { test } = pwt;
test('fails', async ({ page }) => {
console.log('First line');
console.log('Second line');
console.error('Third line');
await expect(true).toBeFalsy();
});
`,
}, { reporter: 'dot,html' });
expect(result.exitCode).toBe(1);
expect(result.failed).toBe(1);
await showReport();
await page.click('text=a.test.js');
await page.click('text=fails');
await page.locator('text=stdout').click();
await expect(page.locator('.attachment-body')).toHaveText('First line\nSecond line');
await page.locator('text=stderr').click();
await expect(page.locator('.attachment-body').nth(1)).toHaveText('Third line');
});