2021-06-07 03:09:53 +03:00
|
|
|
|
/**
|
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-02-01 04:14:59 +03:00
|
|
|
|
import { test, expect, stripAnsi } from './playwright-test-fixtures';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
|
|
|
|
test('should retry failures', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'retry-failures.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('flake', async ({}, testInfo) => {
|
|
|
|
|
// Passes on the second run.
|
|
|
|
|
expect(testInfo.retry).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { retries: 10 });
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.flaky).toBe(1);
|
|
|
|
|
expect(result.results.length).toBe(2);
|
|
|
|
|
expect(result.results[0].workerIndex).toBe(0);
|
|
|
|
|
expect(result.results[0].retry).toBe(0);
|
|
|
|
|
expect(result.results[0].status).toBe('failed');
|
|
|
|
|
expect(result.results[1].workerIndex).toBe(1);
|
|
|
|
|
expect(result.results[1].retry).toBe(1);
|
|
|
|
|
expect(result.results[1].status).toBe('passed');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should retry based on config', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.js': `
|
|
|
|
|
module.exports = { projects: [
|
|
|
|
|
{ retries: 0, name: 'no-retries' },
|
|
|
|
|
{ retries: 2, name: 'two-retries' },
|
|
|
|
|
] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('pass', ({}, testInfo) => {
|
|
|
|
|
// Passes on the third run.
|
|
|
|
|
expect(testInfo.retry).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
|
expect(result.flaky).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.results.length).toBe(4);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should retry timeout', async ({ runInlineTest }) => {
|
|
|
|
|
const { exitCode, passed, failed, output } = await runInlineTest({
|
|
|
|
|
'one-timeout.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('timeout', async () => {
|
|
|
|
|
await new Promise(f => setTimeout(f, 10000));
|
|
|
|
|
});
|
|
|
|
|
`
|
2021-08-10 04:09:11 +03:00
|
|
|
|
}, { timeout: 1000, retries: 2 });
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(exitCode).toBe(1);
|
|
|
|
|
expect(passed).toBe(0);
|
|
|
|
|
expect(failed).toBe(1);
|
2022-02-01 04:14:59 +03:00
|
|
|
|
expect(stripAnsi(output).split('\n')[2]).toBe('××T');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should fail on unexpected pass with retries', async ({ runInlineTest }) => {
|
|
|
|
|
const { exitCode, failed, output } = await runInlineTest({
|
|
|
|
|
'unexpected-pass.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('succeeds', () => {
|
|
|
|
|
test.fail();
|
|
|
|
|
expect(1 + 1).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { retries: 1 });
|
|
|
|
|
expect(exitCode).toBe(1);
|
|
|
|
|
expect(failed).toBe(1);
|
2021-08-25 22:19:50 +03:00
|
|
|
|
expect(output).toContain('Expected to fail, but passed.');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
2021-08-25 22:19:50 +03:00
|
|
|
|
test('should retry unexpected pass', async ({ runInlineTest }) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
|
const { exitCode, passed, failed, output } = await runInlineTest({
|
|
|
|
|
'unexpected-pass.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('succeeds', () => {
|
|
|
|
|
test.fail();
|
|
|
|
|
expect(1 + 1).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { retries: 2 });
|
|
|
|
|
expect(exitCode).toBe(1);
|
|
|
|
|
expect(passed).toBe(0);
|
|
|
|
|
expect(failed).toBe(1);
|
2022-02-01 04:14:59 +03:00
|
|
|
|
expect(stripAnsi(output).split('\n')[2]).toBe('××F');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should not retry expected failure', async ({ runInlineTest }) => {
|
|
|
|
|
const { exitCode, passed, failed, output } = await runInlineTest({
|
|
|
|
|
'expected-failure.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('fails', () => {
|
|
|
|
|
test.fail();
|
|
|
|
|
expect(1 + 1).toBe(3);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('non-empty remaining',() => {
|
|
|
|
|
expect(1 + 1).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { retries: 2 });
|
|
|
|
|
expect(exitCode).toBe(0);
|
|
|
|
|
expect(passed).toBe(2);
|
|
|
|
|
expect(failed).toBe(0);
|
2022-02-01 04:14:59 +03:00
|
|
|
|
expect(stripAnsi(output).split('\n')[2]).toBe('··');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should retry unhandled rejection', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'unhandled-rejection.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('unhandled rejection', async () => {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
throw new Error('Unhandled rejection in the test');
|
|
|
|
|
});
|
2021-07-29 01:43:37 +03:00
|
|
|
|
await new Promise(f => setTimeout(f, 2000));
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { retries: 2 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2022-02-01 04:14:59 +03:00
|
|
|
|
expect(stripAnsi(result.output).split('\n')[2]).toBe('××F');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.output).toContain('Unhandled rejection');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should retry beforeAll failure', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
|
throw new Error('BeforeAll is bugged!');
|
|
|
|
|
});
|
|
|
|
|
test('passing test', async () => {
|
|
|
|
|
});
|
2021-08-24 22:22:16 +03:00
|
|
|
|
test('another passing test', async () => {
|
|
|
|
|
});
|
2021-06-07 03:09:53 +03:00
|
|
|
|
`
|
|
|
|
|
}, { retries: 2 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2021-08-24 22:22:16 +03:00
|
|
|
|
expect(result.skipped).toBe(1);
|
2022-02-01 04:14:59 +03:00
|
|
|
|
expect(stripAnsi(result.output).split('\n')[2]).toBe('×°×°F°');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.output).toContain('BeforeAll is bugged!');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should retry worker fixture setup failure', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'helper.ts': `
|
2021-06-07 08:07:07 +03:00
|
|
|
|
export const test = pwt.test.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
worker: [ async () => {
|
|
|
|
|
throw new Error('worker setup is bugged!');
|
|
|
|
|
}, { scope: 'worker' } ]
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'a.spec.ts': `
|
|
|
|
|
import { test } from './helper';
|
|
|
|
|
test('passing test', async ({ worker }) => {
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { retries: 2 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2022-02-01 04:14:59 +03:00
|
|
|
|
expect(stripAnsi(result.output).split('\n')[2]).toBe('××F');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.output).toContain('worker setup is bugged!');
|
|
|
|
|
});
|