feat(test runner): save traces for beforeAll/afterAll hooks (#10950)

This commit is contained in:
Dmitry Gozman 2021-12-15 16:06:10 -08:00 committed by GitHub
parent 230e0b7049
commit 192071d5bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View file

@ -262,9 +262,8 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
// 3. Determine whether we need the artifacts.
const testFailed = testInfo.status !== testInfo.expectedStatus;
const isHook = !!hookType(testInfo);
const preserveTrace = captureTrace && !isHook && (traceMode === 'on' || (testFailed && traceMode === 'retain-on-failure') || (traceMode === 'on-first-retry' && testInfo.retry === 1));
const captureScreenshots = !isHook && (screenshot === 'on' || (screenshot === 'only-on-failure' && testFailed));
const preserveTrace = captureTrace && (traceMode === 'on' || (testFailed && traceMode === 'retain-on-failure') || (traceMode === 'on-first-retry' && testInfo.retry === 1));
const captureScreenshots = (screenshot === 'on' || (screenshot === 'only-on-failure' && testFailed));
const traceAttachments: string[] = [];
const addTraceAttachment = () => {

View file

@ -145,6 +145,10 @@ test('should work with screenshot: on', async ({ runInlineTest }, testInfo) => {
' test-failed-1.png',
'artifacts-persistent-passing',
' test-finished-1.png',
'artifacts-shared-afterAll-worker0',
' test-finished-1.png',
'artifacts-shared-beforeAll-worker0',
' test-finished-1.png',
'artifacts-shared-shared-failing',
' test-failed-1.png',
'artifacts-shared-shared-passing',
@ -210,6 +214,10 @@ test('should work with trace: on', async ({ runInlineTest }, testInfo) => {
' trace.zip',
'artifacts-persistent-passing',
' trace.zip',
'artifacts-shared-afterAll-worker0',
' trace.zip',
'artifacts-shared-beforeAll-worker0',
' trace.zip',
'artifacts-shared-shared-failing',
' trace.zip',
'artifacts-shared-shared-passing',
@ -269,6 +277,8 @@ test('should work with trace: on-first-retry', async ({ runInlineTest }, testInf
' trace.zip',
'artifacts-persistent-failing-retry1',
' trace.zip',
'artifacts-shared-beforeAll-worker1-retry1',
' trace.zip',
'artifacts-shared-shared-failing-retry1',
' trace.zip',
'artifacts-two-contexts-failing-retry1',

View file

@ -299,9 +299,12 @@ test('should render beforeAll/afterAll hooks', async ({ runInlineTest, page, sho
const result = await runInlineTest({
'a.test.js': `
const { test } = pwt;
test.use({ trace: 'on' });
test.beforeAll(async () => {
});
test.afterAll(async () => {
test.afterAll(async ({ browser }) => {
const page = await browser.newPage();
await page.close();
await test.step('after step', () => {
throw new Error('oh!');
});
@ -328,6 +331,7 @@ test('should render beforeAll/afterAll hooks', async ({ runInlineTest, page, sho
await page.click('text=afterAll');
await expect(page.locator('.tree-item:has-text("after step") svg.color-text-danger')).toHaveCount(1);
await expect(page.locator('img')).toBeVisible();
});
test('should render text attachments as text', async ({ runInlineTest, page, showReport }) => {