test(playwright-test): add initial tests for trace on-first-failure
This commit is contained in:
parent
4d868f6ba8
commit
e4736facf0
|
|
@ -14,9 +14,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { test, expect } from './playwright-test-fixtures';
|
|
||||||
import { parseTrace, parseTraceRaw } from '../config/utils';
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import { parseTrace, parseTraceRaw } from '../config/utils';
|
||||||
|
import { expect, test } from './playwright-test-fixtures';
|
||||||
|
|
||||||
test.describe.configure({ mode: 'parallel' });
|
test.describe.configure({ mode: 'parallel' });
|
||||||
|
|
||||||
|
|
@ -402,7 +402,7 @@ test('should respect PW_TEST_DISABLE_TRACING', async ({ runInlineTest }, testInf
|
||||||
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'))).toBe(false);
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'))).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const mode of ['off', 'retain-on-failure', 'on-first-retry', 'on-all-retries']) {
|
for (const mode of ['off', 'retain-on-failure', 'on-first-retry', 'on-all-retries', 'on-first-failure']) {
|
||||||
test(`trace:${mode} should not create trace zip artifact if page test passed`, async ({ runInlineTest }) => {
|
test(`trace:${mode} should not create trace zip artifact if page test passed`, async ({ runInlineTest }) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.spec.ts': `
|
'a.spec.ts': `
|
||||||
|
|
@ -1034,3 +1034,65 @@ test('should attribute worker fixture teardown to the right test', async ({ runI
|
||||||
' step in foo teardown',
|
' step in foo teardown',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('trace:on-first-failure should create trace if context is closed before failure in the test', 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 }) => {
|
||||||
|
await page.goto('about:blank');
|
||||||
|
await context.close();
|
||||||
|
expect(1).toBe(2);
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, { trace: 'on-first-failure' });
|
||||||
|
const tracePath = test.info().outputPath('test-results', 'a-passing-test', '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 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.afterEach(async ({ page, context }) => {
|
||||||
|
await page.goto('about:blank');
|
||||||
|
await context.close();
|
||||||
|
expect(1).toBe(2);
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, { trace: 'on-first-failure' });
|
||||||
|
const tracePath = test.info().outputPath('test-results', 'a-passing-test', '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 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 }) => {
|
||||||
|
expect(await request.get('${server.EMPTY_PAGE}')).toBeOK();
|
||||||
|
await request.dispose();
|
||||||
|
expect(1).toBe(2);
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, { trace: 'on-first-failure' });
|
||||||
|
const tracePath = test.info().outputPath('test-results', 'a-passing-test', 'trace.zip');
|
||||||
|
const trace = await parseTrace(tracePath);
|
||||||
|
expect(trace.apiNames).toContain('apiRequestContext.get');
|
||||||
|
expect(result.failed).toBe(1);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue