test: correct tests for on-first-failure mode

This commit is contained in:
Stevan Freeborn 2024-02-23 19:58:00 -06:00
parent 05cdbdf362
commit 4fc2d1e24c

View file

@ -1034,21 +1034,39 @@ test('should attribute worker fixture teardown to the right test', async ({ runI
]);
});
test('trace:on-first-failure should create trace if context is closed before failure in the test', async ({ runInlineTest }) => {
test('trace:on-first-failure should create trace but only on first failure', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { trace: 'on-first-failure' } };
`,
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('passing test', async ({ page, context }) => {
test('fail', async ({ page }) => {
await page.goto('about:blank');
expect(true).toBe(false);
});
`,
}, { trace: 'on-first-failure', retries: 1 });
const retryTracePath = test.info().outputPath('test-results', 'a-fail-retry1', 'trace.zip');
const retryTraceExists = fs.existsSync(retryTracePath);
expect(retryTraceExists).toBe(false);
const tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');
const trace = await parseTrace(tracePath);
expect(trace.apiNames).toContain('page.goto');
expect(result.failed).toBe(1);
});
test('trace:on-first-failure should create trace if context is closed before failure in the test', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('fail', async ({ page, context }) => {
await page.goto('about:blank');
await context.close();
expect(1).toBe(2);
});
`,
}, { trace: 'retain-on-failure' });
const tracePath = test.info().outputPath('test-results', 'a-passing-test', 'trace.zip');
}, { trace: 'on-first-failure' });
const tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');
const trace = await parseTrace(tracePath);
expect(trace.apiNames).toContain('page.goto');
expect(result.failed).toBe(1);
@ -1056,12 +1074,9 @@ test('trace:on-first-failure should create trace if context is closed before fai
test('trace:on-first-failure should create trace if context is closed before failure in afterEach', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { trace: 'on-first-failure' } };
`,
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('passing test', async ({ page, context }) => {
test('fail', async ({ page, context }) => {
});
test.afterEach(async ({ page, context }) => {
await page.goto('about:blank');
@ -1069,8 +1084,8 @@ test('trace:on-first-failure should create trace if context is closed before fai
expect(1).toBe(2);
});
`,
}, { trace: 'retain-on-failure' });
const tracePath = test.info().outputPath('test-results', 'a-passing-test', 'trace.zip');
}, { trace: 'on-first-failure' });
const tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');
const trace = await parseTrace(tracePath);
expect(trace.apiNames).toContain('page.goto');
expect(result.failed).toBe(1);
@ -1078,19 +1093,16 @@ test('trace:on-first-failure should create trace if context is closed before fai
test('trace:on-first-failure should create trace if request context is disposed before failure', async ({ runInlineTest, server }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { trace: 'on-first-failure' } };
`,
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('passing test', async ({ request }) => {
test('fail', async ({ request }) => {
expect(await request.get('${server.EMPTY_PAGE}')).toBeOK();
await request.dispose();
expect(1).toBe(2);
});
`,
}, { trace: 'retain-on-failure' });
const tracePath = test.info().outputPath('test-results', 'a-passing-test', 'trace.zip');
}, { trace: 'on-first-failure' });
const tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');
const trace = await parseTrace(tracePath);
expect(trace.apiNames).toContain('apiRequestContext.get');
expect(result.failed).toBe(1);