2021-06-07 03:09:53 +03:00
|
|
|
|
/**
|
|
|
|
|
* Copyright Microsoft Corporation. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-02-08 02:11:44 +03:00
|
|
|
|
import { test, expect } from './playwright-test-fixtures';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
|
|
|
|
test('hooks should work with fixtures', async ({ runInlineTest }) => {
|
|
|
|
|
const { results } = await runInlineTest({
|
|
|
|
|
'helper.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base } from '@playwright/test';
|
|
|
|
|
export { expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
global.logs = [];
|
2021-08-09 23:26:33 +03:00
|
|
|
|
let counter = 0;
|
2023-02-15 06:20:56 +03:00
|
|
|
|
export const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
w: [ async ({}, run) => {
|
|
|
|
|
global.logs.push('+w');
|
|
|
|
|
await run(17);
|
|
|
|
|
global.logs.push('-w');
|
|
|
|
|
}, { scope: 'worker' }],
|
|
|
|
|
|
|
|
|
|
t: async ({}, run) => {
|
|
|
|
|
global.logs.push('+t');
|
2021-08-09 23:26:33 +03:00
|
|
|
|
await run(42 + counter);
|
|
|
|
|
++counter;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
global.logs.push('-t');
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
const { test, expect } = require('./helper');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test.describe('suite', () => {
|
2021-08-09 23:26:33 +03:00
|
|
|
|
test.beforeAll(async ({ w, t }) => {
|
|
|
|
|
global.logs.push('beforeAll-' + w + '-' + t);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
2023-05-02 21:04:51 +03:00
|
|
|
|
test.beforeAll(async ({ w, t }) => {
|
|
|
|
|
global.logs.push('beforeAll2-' + w + '-' + t);
|
|
|
|
|
});
|
2021-08-09 23:26:33 +03:00
|
|
|
|
test.afterAll(async ({ w, t }) => {
|
|
|
|
|
global.logs.push('afterAll-' + w + '-' + t);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
2023-05-02 21:04:51 +03:00
|
|
|
|
test.afterAll(async ({ w, t }) => {
|
|
|
|
|
global.logs.push('afterAll2-' + w + '-' + t);
|
|
|
|
|
});
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
2021-08-09 23:26:33 +03:00
|
|
|
|
test.beforeEach(async ({ w, t }) => {
|
|
|
|
|
global.logs.push('beforeEach-' + w + '-' + t);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
2021-08-09 23:26:33 +03:00
|
|
|
|
test.afterEach(async ({ w, t }) => {
|
|
|
|
|
global.logs.push('afterEach-' + w + '-' + t);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
2021-08-09 23:26:33 +03:00
|
|
|
|
test('one', async ({ w, t }) => {
|
|
|
|
|
global.logs.push('test-' + w + '-' + t);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-09 23:26:33 +03:00
|
|
|
|
test('two', async ({ t }) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(global.logs).toEqual([
|
|
|
|
|
'+w',
|
|
|
|
|
'+t',
|
2021-08-09 23:26:33 +03:00
|
|
|
|
'beforeAll-17-42',
|
2023-05-02 21:04:51 +03:00
|
|
|
|
'-t',
|
|
|
|
|
'+t',
|
|
|
|
|
'beforeAll2-17-43',
|
|
|
|
|
'-t',
|
|
|
|
|
'+t',
|
|
|
|
|
'beforeEach-17-44',
|
|
|
|
|
'test-17-44',
|
|
|
|
|
'afterEach-17-44',
|
|
|
|
|
'-t',
|
|
|
|
|
'+t',
|
|
|
|
|
'afterAll-17-45',
|
|
|
|
|
'-t',
|
|
|
|
|
'+t',
|
|
|
|
|
'afterAll2-17-46',
|
2021-06-07 03:09:53 +03:00
|
|
|
|
'-t',
|
|
|
|
|
'+t',
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(results[0].status).toBe('passed');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('afterEach failure should not prevent other hooks and fixtures teardown', async ({ runInlineTest }) => {
|
|
|
|
|
const report = await runInlineTest({
|
|
|
|
|
'helper.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base } from '@playwright/test';
|
|
|
|
|
export { expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
global.logs = [];
|
2023-02-15 06:20:56 +03:00
|
|
|
|
export const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: async ({}, run) => {
|
|
|
|
|
console.log('+t');
|
|
|
|
|
await run();
|
|
|
|
|
console.log('-t');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
const { test, expect } = require('./helper');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test.describe('suite', () => {
|
2022-02-28 22:42:47 +03:00
|
|
|
|
test.afterEach(async () => {
|
2022-03-01 20:11:17 +03:00
|
|
|
|
console.log('afterEach2');
|
|
|
|
|
throw new Error('afterEach2');
|
2022-02-28 22:42:47 +03:00
|
|
|
|
});
|
2022-03-09 03:35:14 +03:00
|
|
|
|
test.afterEach(async () => {
|
|
|
|
|
console.log('afterEach1');
|
|
|
|
|
});
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('one', async ({foo}) => {
|
|
|
|
|
console.log('test');
|
|
|
|
|
expect(true).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(report.output).toContain('+t\ntest\nafterEach2\nafterEach1\n-t');
|
|
|
|
|
expect(report.results[0].error.message).toContain('afterEach2');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('beforeEach failure should prevent the test, but not other hooks', async ({ runInlineTest }) => {
|
|
|
|
|
const report = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test.describe('suite', () => {
|
|
|
|
|
test.beforeEach(async ({}) => {
|
|
|
|
|
console.log('beforeEach1');
|
|
|
|
|
});
|
|
|
|
|
test.beforeEach(async ({}) => {
|
|
|
|
|
console.log('beforeEach2');
|
|
|
|
|
throw new Error('beforeEach2');
|
|
|
|
|
});
|
|
|
|
|
test.afterEach(async ({}) => {
|
|
|
|
|
console.log('afterEach');
|
|
|
|
|
});
|
|
|
|
|
test('one', async ({}) => {
|
|
|
|
|
console.log('test');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(report.output).toContain('beforeEach1\nbeforeEach2\nafterEach');
|
|
|
|
|
expect(report.results[0].error.message).toContain('beforeEach2');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('beforeAll should be run once', async ({ runInlineTest }) => {
|
2021-12-15 21:39:49 +03:00
|
|
|
|
const result = await runInlineTest({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test.describe('suite1', () => {
|
|
|
|
|
let counter = 0;
|
|
|
|
|
test.beforeAll(async () => {
|
2021-12-15 21:39:49 +03:00
|
|
|
|
console.log('\\n%%beforeAll1-' + (++counter));
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
test.describe('suite2', () => {
|
|
|
|
|
test.beforeAll(async () => {
|
2021-12-15 21:39:49 +03:00
|
|
|
|
console.log('\\n%%beforeAll2');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
test('one', async ({}) => {
|
2021-12-15 21:39:49 +03:00
|
|
|
|
console.log('\\n%%test');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'beforeAll1-1',
|
|
|
|
|
'beforeAll2',
|
|
|
|
|
'test',
|
2021-12-15 21:39:49 +03:00
|
|
|
|
]);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('beforeEach should be able to skip a test', async ({ runInlineTest }) => {
|
|
|
|
|
const { passed, skipped, exitCode } = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test.beforeEach(async ({}, testInfo) => {
|
|
|
|
|
testInfo.skip(testInfo.title === 'test2');
|
|
|
|
|
});
|
|
|
|
|
test('test1', async () => {});
|
|
|
|
|
test('test2', async () => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(exitCode).toBe(0);
|
|
|
|
|
expect(passed).toBe(1);
|
|
|
|
|
expect(skipped).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('beforeAll from a helper file should throw', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'my-test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
export const test = base;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test.beforeAll(() => {});
|
|
|
|
|
`,
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
import { test } from './my-test';
|
2022-10-19 23:06:11 +03:00
|
|
|
|
test.extend({});
|
2021-06-07 03:09:53 +03:00
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
|
|
|
|
import { test } from './my-test';
|
|
|
|
|
test('should work', async () => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
2022-02-19 05:25:18 +03:00
|
|
|
|
expect(result.output).toContain('Playwright Test did not expect test.beforeAll() to be called here');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
2021-07-16 08:02:10 +03:00
|
|
|
|
|
|
|
|
|
test('beforeAll hooks are skipped when no tests in the suite are run', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-07-16 08:02:10 +03:00
|
|
|
|
test.describe('suite1', () => {
|
|
|
|
|
test.beforeAll(() => {
|
|
|
|
|
console.log('\\n%%beforeAll1');
|
|
|
|
|
});
|
|
|
|
|
test('skipped', () => {});
|
|
|
|
|
});
|
|
|
|
|
test.describe('suite2', () => {
|
|
|
|
|
test.beforeAll(() => {
|
|
|
|
|
console.log('\\n%%beforeAll2');
|
|
|
|
|
});
|
|
|
|
|
test.only('passed', () => {});
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
expect(result.output).toContain('%%beforeAll2');
|
|
|
|
|
expect(result.output).not.toContain('%%beforeAll1');
|
|
|
|
|
});
|
2021-08-09 23:26:33 +03:00
|
|
|
|
|
2022-02-09 03:36:30 +03:00
|
|
|
|
test('beforeAll/afterAll hooks are skipped when no tests in the suite are run 2', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-02-09 03:36:30 +03:00
|
|
|
|
test.beforeAll(() => {
|
|
|
|
|
console.log('\\n%%beforeAll1');
|
|
|
|
|
});
|
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
console.log('\\n%%afterAll1');
|
|
|
|
|
});
|
|
|
|
|
test.skip('skipped1', () => {});
|
|
|
|
|
test.describe('inner', () => {
|
|
|
|
|
test.beforeAll(() => {
|
|
|
|
|
console.log('\\n%%beforeAll2');
|
|
|
|
|
});
|
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
console.log('\\n%%afterAll2');
|
|
|
|
|
});
|
|
|
|
|
test.skip('skipped2', () => {});
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
|
expect(result.skipped).toBe(2);
|
|
|
|
|
expect(result.output).not.toContain('%%beforeAll');
|
|
|
|
|
expect(result.output).not.toContain('%%afterAll');
|
|
|
|
|
});
|
|
|
|
|
|
2022-09-12 19:27:53 +03:00
|
|
|
|
test('run hooks after failure', async ({ runInlineTest }) => {
|
2021-08-10 20:54:05 +03:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-08-10 20:54:05 +03:00
|
|
|
|
test.describe('suite', () => {
|
|
|
|
|
test('faled', ({}) => {
|
|
|
|
|
console.log('\\n%%test');
|
|
|
|
|
expect(1).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
test.afterEach(() => {
|
|
|
|
|
console.log('\\n%%afterEach-1');
|
|
|
|
|
});
|
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
console.log('\\n%%afterAll-1');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
test.afterEach(async () => {
|
|
|
|
|
await new Promise(f => setTimeout(f, 1000));
|
|
|
|
|
console.log('\\n%%afterEach-2');
|
|
|
|
|
});
|
|
|
|
|
test.afterAll(async () => {
|
|
|
|
|
await new Promise(f => setTimeout(f, 1000));
|
|
|
|
|
console.log('\\n%%afterAll-2');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'test',
|
|
|
|
|
'afterEach-1',
|
|
|
|
|
'afterEach-2',
|
|
|
|
|
'afterAll-1',
|
|
|
|
|
'afterAll-2',
|
2021-08-10 20:54:05 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-09 23:26:33 +03:00
|
|
|
|
test('beforeAll hook should get retry index of the first test', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-08-09 23:26:33 +03:00
|
|
|
|
test.beforeAll(({}, testInfo) => {
|
|
|
|
|
console.log('\\n%%beforeall-retry-' + testInfo.retry);
|
|
|
|
|
});
|
|
|
|
|
test('passed', ({}, testInfo) => {
|
|
|
|
|
console.log('\\n%%test-retry-' + testInfo.retry);
|
|
|
|
|
expect(testInfo.retry).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { retries: 1 });
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.flaky).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'beforeall-retry-0',
|
|
|
|
|
'test-retry-0',
|
|
|
|
|
'beforeall-retry-1',
|
|
|
|
|
'test-retry-1',
|
2021-08-09 23:26:33 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
2021-08-10 00:21:53 +03:00
|
|
|
|
|
2022-03-09 03:35:14 +03:00
|
|
|
|
test('afterAll exception should fail the test', async ({ runInlineTest }) => {
|
2021-08-10 00:21:53 +03:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-08-10 00:21:53 +03:00
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
throw new Error('From the afterAll');
|
|
|
|
|
});
|
|
|
|
|
test('passed', () => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
2022-03-09 03:35:14 +03:00
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2021-08-10 00:21:53 +03:00
|
|
|
|
expect(result.output).toContain('From the afterAll');
|
|
|
|
|
});
|
2021-08-10 20:54:05 +03:00
|
|
|
|
|
|
|
|
|
test('max-failures should still run afterEach/afterAll', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-08-10 20:54:05 +03:00
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
console.log('\\n%%afterAll');
|
|
|
|
|
});
|
|
|
|
|
test.afterEach(() => {
|
|
|
|
|
console.log('\\n%%afterEach');
|
|
|
|
|
});
|
|
|
|
|
test('failed', async () => {
|
|
|
|
|
console.log('\\n%%test');
|
|
|
|
|
test.expect(1).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
test('skipped', async () => {
|
|
|
|
|
console.log('\\n%%skipped');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { 'max-failures': 1 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.skipped).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'test',
|
|
|
|
|
'afterEach',
|
|
|
|
|
'afterAll',
|
2021-08-10 20:54:05 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('beforeAll failure should prevent the test, but not afterAll', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-08-10 20:54:05 +03:00
|
|
|
|
test.beforeAll(() => {
|
|
|
|
|
console.log('\\n%%beforeAll');
|
|
|
|
|
throw new Error('From a beforeAll');
|
|
|
|
|
});
|
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
console.log('\\n%%afterAll');
|
|
|
|
|
});
|
2022-03-09 03:35:14 +03:00
|
|
|
|
test('failed', () => {
|
|
|
|
|
console.log('\\n%%test1');
|
|
|
|
|
});
|
2021-08-10 20:54:05 +03:00
|
|
|
|
test('skipped', () => {
|
2022-03-09 03:35:14 +03:00
|
|
|
|
console.log('\\n%%test2');
|
2021-08-10 20:54:05 +03:00
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2022-03-09 03:35:14 +03:00
|
|
|
|
expect(result.skipped).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'beforeAll',
|
|
|
|
|
'afterAll',
|
2021-08-10 20:54:05 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
2021-08-12 19:08:56 +03:00
|
|
|
|
|
|
|
|
|
test('fixture error should not prevent afterAll', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-08-12 19:08:56 +03:00
|
|
|
|
foo: async ({}, use) => {
|
|
|
|
|
await use('foo');
|
|
|
|
|
throw new Error('bad fixture');
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
test('good test', ({ foo }) => {
|
|
|
|
|
console.log('\\n%%test');
|
|
|
|
|
});
|
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
console.log('\\n%%afterAll');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.output).toContain('bad fixture');
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'test',
|
|
|
|
|
'afterAll',
|
2021-08-12 19:08:56 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('afterEach failure should not prevent afterAll', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-08-12 19:08:56 +03:00
|
|
|
|
test('good test', ({ }) => {
|
|
|
|
|
console.log('\\n%%test');
|
|
|
|
|
});
|
|
|
|
|
test.afterEach(() => {
|
|
|
|
|
console.log('\\n%%afterEach');
|
|
|
|
|
throw new Error('bad afterEach');
|
|
|
|
|
})
|
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
console.log('\\n%%afterAll');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.output).toContain('bad afterEach');
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'test',
|
|
|
|
|
'afterEach',
|
|
|
|
|
'afterAll',
|
2021-08-12 19:08:56 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
2021-08-23 19:21:40 +03:00
|
|
|
|
|
|
|
|
|
test('afterAll error should not mask beforeAll', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-08-23 19:21:40 +03:00
|
|
|
|
test.beforeAll(() => {
|
|
|
|
|
throw new Error('from beforeAll');
|
|
|
|
|
});
|
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
throw new Error('from afterAll');
|
|
|
|
|
})
|
|
|
|
|
test('test', () => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.output).toContain('from beforeAll');
|
|
|
|
|
});
|
2021-08-28 17:19:45 +03:00
|
|
|
|
|
2022-03-09 03:35:14 +03:00
|
|
|
|
test('beforeAll timeout should be reported and prevent more tests', async ({ runInlineTest }) => {
|
2021-08-28 17:19:45 +03:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-08-28 17:19:45 +03:00
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
|
console.log('\\n%%beforeAll');
|
|
|
|
|
await new Promise(f => setTimeout(f, 5000));
|
|
|
|
|
});
|
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
console.log('\\n%%afterAll');
|
|
|
|
|
});
|
2022-03-09 03:35:14 +03:00
|
|
|
|
test('failed', () => {
|
|
|
|
|
console.log('\\n%%test1');
|
|
|
|
|
});
|
2021-08-28 17:19:45 +03:00
|
|
|
|
test('skipped', () => {
|
2022-03-09 03:35:14 +03:00
|
|
|
|
console.log('\\n%%test2');
|
2021-08-28 17:19:45 +03:00
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { timeout: 1000 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2022-03-09 03:35:14 +03:00
|
|
|
|
expect(result.skipped).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'beforeAll',
|
|
|
|
|
'afterAll',
|
2021-08-28 17:19:45 +03:00
|
|
|
|
]);
|
2022-07-01 03:05:08 +03:00
|
|
|
|
expect(result.output).toContain('"beforeAll" hook timeout of 1000ms exceeded.');
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain(`a.test.js:3:12`);
|
|
|
|
|
expect(result.output).toContain(`> 3 | test.beforeAll(async () => {`);
|
2021-08-28 17:19:45 +03:00
|
|
|
|
});
|
|
|
|
|
|
2022-03-09 03:35:14 +03:00
|
|
|
|
test('afterAll timeout should be reported, run other afterAll hooks, and continue testing', async ({ runInlineTest }, testInfo) => {
|
2021-08-28 17:19:45 +03:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-03-09 03:35:14 +03:00
|
|
|
|
test.describe('suite', () => {
|
|
|
|
|
test.afterAll(async () => {
|
|
|
|
|
console.log('\\n%%afterAll1');
|
|
|
|
|
await new Promise(f => setTimeout(f, 5000));
|
|
|
|
|
});
|
|
|
|
|
test('runs', () => {
|
2022-03-09 06:05:23 +03:00
|
|
|
|
test.setTimeout(2000);
|
2022-03-09 03:35:14 +03:00
|
|
|
|
console.log('\\n%%test1');
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-08-28 17:19:45 +03:00
|
|
|
|
test.afterAll(async () => {
|
2022-03-09 03:35:14 +03:00
|
|
|
|
console.log('\\n%%afterAll2');
|
2021-08-28 17:19:45 +03:00
|
|
|
|
});
|
2022-03-09 03:35:14 +03:00
|
|
|
|
test('does not run', () => {
|
|
|
|
|
console.log('\\n%%test2');
|
2021-08-28 17:19:45 +03:00
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { timeout: 1000 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(1);
|
2022-03-09 03:35:14 +03:00
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.skipped).toBe(0);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'test1',
|
|
|
|
|
'afterAll1',
|
|
|
|
|
'afterAll2',
|
|
|
|
|
'test2',
|
|
|
|
|
'afterAll2',
|
2021-08-28 17:19:45 +03:00
|
|
|
|
]);
|
2022-07-01 03:05:08 +03:00
|
|
|
|
expect(result.output).toContain('"afterAll" hook timeout of 1000ms exceeded.');
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain(`a.test.js:4:14`);
|
|
|
|
|
expect(result.output).toContain(`> 4 | test.afterAll(async () => {`);
|
2021-08-28 17:19:45 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('beforeAll and afterAll timeouts at the same time should be reported', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-08-28 17:19:45 +03:00
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
|
console.log('\\n%%beforeAll');
|
|
|
|
|
await new Promise(f => setTimeout(f, 5000));
|
|
|
|
|
});
|
|
|
|
|
test.afterAll(async () => {
|
|
|
|
|
console.log('\\n%%afterAll');
|
|
|
|
|
await new Promise(f => setTimeout(f, 5000));
|
|
|
|
|
});
|
|
|
|
|
test('skipped', () => {
|
|
|
|
|
console.log('\\n%%test');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { timeout: 1000 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'beforeAll',
|
|
|
|
|
'afterAll',
|
2021-08-28 17:19:45 +03:00
|
|
|
|
]);
|
2022-07-01 03:05:08 +03:00
|
|
|
|
expect(result.output).toContain('"beforeAll" hook timeout of 1000ms exceeded.');
|
2021-08-28 17:19:45 +03:00
|
|
|
|
});
|
2021-10-23 02:32:22 +03:00
|
|
|
|
|
2021-11-11 03:02:27 +03:00
|
|
|
|
test('afterEach should get the test status and duration right away', async ({ runInlineTest }) => {
|
2021-10-23 02:32:22 +03:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-10-23 02:32:22 +03:00
|
|
|
|
test.afterEach(({}, testInfo) => {
|
2021-11-11 03:02:27 +03:00
|
|
|
|
const duration = testInfo.duration ? 'XXms' : 'none';
|
|
|
|
|
console.log('\\n%%' + testInfo.title + ': ' + testInfo.status + '; ' + duration);
|
2021-10-23 02:32:22 +03:00
|
|
|
|
});
|
|
|
|
|
test('failing', () => {
|
|
|
|
|
throw new Error('Oh my!');
|
|
|
|
|
});
|
|
|
|
|
test('timing out', async () => {
|
|
|
|
|
test.setTimeout(100);
|
|
|
|
|
await new Promise(() => {});
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(2);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'failing: failed; XXms',
|
|
|
|
|
'timing out: timedOut; XXms',
|
2021-10-23 02:32:22 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
2021-10-26 00:17:27 +03:00
|
|
|
|
|
|
|
|
|
test('uncaught error in beforeEach should not be masked by another error', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-10-26 00:17:27 +03:00
|
|
|
|
foo: async ({}, use) => {
|
|
|
|
|
let cb;
|
|
|
|
|
await use(new Promise((f, r) => cb = r));
|
|
|
|
|
cb(new Error('Oh my!'));
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
test.beforeEach(async ({ foo }, testInfo) => {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
expect(1).toBe(2);
|
|
|
|
|
}, 0);
|
|
|
|
|
await foo;
|
|
|
|
|
});
|
|
|
|
|
test('passing', () => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.output).toContain('Expected: 2');
|
|
|
|
|
expect(result.output).toContain('Received: 1');
|
2021-10-26 00:17:27 +03:00
|
|
|
|
});
|
2021-11-19 01:36:55 +03:00
|
|
|
|
|
|
|
|
|
test('should report error from fixture teardown when beforeAll times out', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-11-19 01:36:55 +03:00
|
|
|
|
foo: async ({}, use) => {
|
|
|
|
|
let cb;
|
|
|
|
|
await use(new Promise((f, r) => cb = r));
|
|
|
|
|
cb(new Error('Oh my!'));
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
test.beforeAll(async ({ foo }, testInfo) => {
|
|
|
|
|
await foo;
|
|
|
|
|
});
|
|
|
|
|
test('passing', () => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { timeout: 1000 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.output).toContain('"beforeAll" hook timeout of 1000ms exceeded.');
|
|
|
|
|
expect(result.output).toContain('Error: Oh my!');
|
2021-11-19 01:36:55 +03:00
|
|
|
|
});
|
2021-12-15 21:39:49 +03:00
|
|
|
|
|
|
|
|
|
test('should not hang and report results when worker process suddenly exits during afterAll', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-03-09 03:35:14 +03:00
|
|
|
|
test('failing due to afterall', () => {});
|
2021-12-15 21:39:49 +03:00
|
|
|
|
test.afterAll(() => { process.exit(0); });
|
|
|
|
|
`
|
2022-07-14 01:11:56 +03:00
|
|
|
|
}, { reporter: 'line' });
|
2021-12-15 21:39:49 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
2022-03-09 03:35:14 +03:00
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2022-12-21 20:36:59 +03:00
|
|
|
|
expect(result.output).toContain('Internal error: worker process exited unexpectedly');
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain('[1/1] a.spec.js:3:11 › failing due to afterall');
|
2022-03-09 03:35:14 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('unhandled rejection during beforeAll should be reported and prevent more tests', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-03-09 03:35:14 +03:00
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
|
console.log('\\n%%beforeAll');
|
|
|
|
|
Promise.resolve().then(() => {
|
|
|
|
|
throw new Error('Oh my');
|
|
|
|
|
});
|
2023-05-23 23:31:23 +03:00
|
|
|
|
await new Promise(f => setTimeout(f, 1000));
|
2022-03-09 03:35:14 +03:00
|
|
|
|
});
|
|
|
|
|
test.afterAll(() => {
|
|
|
|
|
console.log('\\n%%afterAll');
|
|
|
|
|
});
|
|
|
|
|
test('failed', () => {
|
|
|
|
|
console.log('\\n%%test1');
|
|
|
|
|
});
|
|
|
|
|
test('skipped', () => {
|
|
|
|
|
console.log('\\n%%test2');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.skipped).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'beforeAll',
|
|
|
|
|
'afterAll',
|
2022-03-09 03:35:14 +03:00
|
|
|
|
]);
|
|
|
|
|
expect(result.output).toContain('Error: Oh my');
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain(`> 6 | throw new Error('Oh my');`);
|
2022-03-01 02:09:04 +03:00
|
|
|
|
});
|
2022-03-09 06:05:23 +03:00
|
|
|
|
|
|
|
|
|
test('beforeAll and afterAll should have a separate timeout', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-03-09 06:05:23 +03:00
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
|
console.log('\\n%%beforeAll');
|
2023-05-24 23:46:28 +03:00
|
|
|
|
await new Promise(f => setTimeout(f, 1600));
|
2022-03-09 06:05:23 +03:00
|
|
|
|
});
|
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
|
console.log('\\n%%beforeAll2');
|
2023-05-24 23:46:28 +03:00
|
|
|
|
await new Promise(f => setTimeout(f, 1600));
|
2022-03-09 06:05:23 +03:00
|
|
|
|
});
|
|
|
|
|
test('passed', async () => {
|
|
|
|
|
console.log('\\n%%test');
|
2023-05-24 23:46:28 +03:00
|
|
|
|
await new Promise(f => setTimeout(f, 1600));
|
2022-03-09 06:05:23 +03:00
|
|
|
|
});
|
|
|
|
|
test.afterAll(async () => {
|
|
|
|
|
console.log('\\n%%afterAll');
|
2023-05-24 23:46:28 +03:00
|
|
|
|
await new Promise(f => setTimeout(f, 1600));
|
2022-03-09 06:05:23 +03:00
|
|
|
|
});
|
|
|
|
|
test.afterAll(async () => {
|
|
|
|
|
console.log('\\n%%afterAll2');
|
2023-05-24 23:46:28 +03:00
|
|
|
|
await new Promise(f => setTimeout(f, 1600));
|
2022-03-09 06:05:23 +03:00
|
|
|
|
});
|
|
|
|
|
`,
|
2023-05-24 23:46:28 +03:00
|
|
|
|
}, { timeout: '3000' });
|
2022-03-09 06:05:23 +03:00
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'beforeAll',
|
|
|
|
|
'beforeAll2',
|
|
|
|
|
'test',
|
|
|
|
|
'afterAll',
|
|
|
|
|
'afterAll2',
|
2022-03-09 06:05:23 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('test.setTimeout should work separately in beforeAll', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-03-09 06:05:23 +03:00
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
|
console.log('\\n%%beforeAll');
|
2022-11-29 23:54:53 +03:00
|
|
|
|
test.setTimeout(1000);
|
2022-03-09 06:05:23 +03:00
|
|
|
|
});
|
|
|
|
|
test('passed', async () => {
|
|
|
|
|
console.log('\\n%%test');
|
2022-11-29 23:54:53 +03:00
|
|
|
|
await new Promise(f => setTimeout(f, 2000));
|
2022-03-09 06:05:23 +03:00
|
|
|
|
});
|
|
|
|
|
`,
|
2022-11-29 23:54:53 +03:00
|
|
|
|
}, { timeout: 3000 });
|
2022-03-09 06:05:23 +03:00
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'beforeAll',
|
|
|
|
|
'test',
|
2022-03-09 06:05:23 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('test.setTimeout should work separately in afterAll', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-03-09 06:05:23 +03:00
|
|
|
|
test('passed', async () => {
|
|
|
|
|
console.log('\\n%%test');
|
|
|
|
|
});
|
|
|
|
|
test.afterAll(async () => {
|
|
|
|
|
console.log('\\n%%afterAll');
|
2022-10-07 02:23:40 +03:00
|
|
|
|
test.setTimeout(3000);
|
|
|
|
|
await new Promise(f => setTimeout(f, 2000));
|
2022-03-09 06:05:23 +03:00
|
|
|
|
});
|
|
|
|
|
`,
|
2022-10-07 02:23:40 +03:00
|
|
|
|
}, { timeout: '1000' });
|
2022-03-09 06:05:23 +03:00
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'test',
|
|
|
|
|
'afterAll',
|
2022-03-09 06:05:23 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
2022-03-09 07:29:31 +03:00
|
|
|
|
|
|
|
|
|
test('beforeAll failure should only prevent tests that are affected', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-03-09 07:29:31 +03:00
|
|
|
|
test.describe('suite', () => {
|
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
|
console.log('\\n%%beforeAll');
|
|
|
|
|
throw new Error('oh my');
|
|
|
|
|
});
|
|
|
|
|
test('failed', () => {
|
|
|
|
|
console.log('\\n%%test1');
|
|
|
|
|
});
|
|
|
|
|
test('skipped', () => {
|
|
|
|
|
console.log('\\n%%test2');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
test('passed', () => {
|
|
|
|
|
console.log('\\n%%test3');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.skipped).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'beforeAll',
|
|
|
|
|
'test3',
|
2022-03-09 07:29:31 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
2022-07-12 07:33:56 +03:00
|
|
|
|
|
|
|
|
|
test('afterAll should run if last test was skipped', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-07-12 07:33:56 +03:00
|
|
|
|
test.afterAll(() => console.log('after-all'));
|
|
|
|
|
test('test1', () => {});
|
|
|
|
|
test.skip('test2', () => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.skipped).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
expect(result.output).toContain('after-all');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('afterAll should run if last test was skipped 2', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-07-12 07:33:56 +03:00
|
|
|
|
test.afterAll(() => console.log('after-all'));
|
|
|
|
|
test('test1', () => {});
|
|
|
|
|
test('test2', () => { test.skip(); });
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.skipped).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
expect(result.output).toContain('after-all');
|
|
|
|
|
});
|
2022-08-05 04:49:23 +03:00
|
|
|
|
|
|
|
|
|
test('afterEach timeout after skipped test should be reported', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-08-05 04:49:23 +03:00
|
|
|
|
test.afterEach(async () => {
|
|
|
|
|
await new Promise(() => {});
|
|
|
|
|
});
|
|
|
|
|
test('skipped', () => { test.skip(); });
|
|
|
|
|
`,
|
|
|
|
|
}, { timeout: 2000 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.output).toContain('Test timeout of 2000ms exceeded while running "afterEach" hook.');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('afterEach exception after skipped test should be reported', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-08-05 04:49:23 +03:00
|
|
|
|
test.afterEach(async () => {
|
|
|
|
|
throw new Error('oh my!');
|
|
|
|
|
});
|
|
|
|
|
test('skipped', () => { test.skip(); });
|
|
|
|
|
`,
|
|
|
|
|
}, { timeout: 2000 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.output).toContain('Error: oh my!');
|
|
|
|
|
});
|
2023-01-05 01:13:49 +03:00
|
|
|
|
|
|
|
|
|
test('afterAll should be run for test.skip', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2023-01-05 01:13:49 +03:00
|
|
|
|
test.describe('suite1', () => {
|
|
|
|
|
test.beforeAll(() => console.log('\\n%%beforeAll1'));
|
|
|
|
|
test.afterAll(() => console.log('\\n%%afterAll1'));
|
|
|
|
|
test('test1', () => console.log('\\n%%test1'));
|
|
|
|
|
test.skip('test2', () => {});
|
|
|
|
|
test.skip('test2.5', () => {});
|
|
|
|
|
});
|
|
|
|
|
test.describe('suite2', () => {
|
|
|
|
|
test.beforeAll(() => console.log('\\n%%beforeAll2'));
|
|
|
|
|
test.afterAll(() => console.log('\\n%%afterAll2'));
|
|
|
|
|
test('test3', () => console.log('\\n%%test3'));
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'beforeAll1',
|
|
|
|
|
'test1',
|
|
|
|
|
'afterAll1',
|
|
|
|
|
'beforeAll2',
|
|
|
|
|
'test3',
|
|
|
|
|
'afterAll2',
|
2023-01-05 01:13:49 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|