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.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-02-08 02:11:44 +03:00
|
|
|
|
import { test, expect, countTimes } from './playwright-test-fixtures';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
|
|
|
|
test('should handle fixture timeout', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
timeout: async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
await new Promise(f => setTimeout(f, 100000));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('fixture timeout', async ({timeout}) => {
|
|
|
|
|
expect(1).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('failing fixture timeout', async ({timeout}) => {
|
|
|
|
|
expect(1).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { timeout: 500 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
2023-03-11 00:45:47 +03:00
|
|
|
|
expect(result.output).toContain('Test finished within timeout of 500ms, but tearing down "timeout" ran out of time.');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.failed).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle worker fixture timeout', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
timeout: [async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
await new Promise(f => setTimeout(f, 100000));
|
|
|
|
|
}, { scope: 'worker' }]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('fails', async ({timeout}) => {
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { timeout: 500 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
2022-07-08 21:44:37 +03:00
|
|
|
|
expect(result.output).toContain('Worker teardown timeout of 500ms exceeded while tearing down "timeout".');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle worker fixture error', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
failure: [async ({}, runTest) => {
|
|
|
|
|
throw new Error('Worker failed');
|
|
|
|
|
}, { scope: 'worker' }]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('fails', async ({failure}) => {
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.output).toContain('Worker failed');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle worker tear down fixture error', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
failure: [async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
throw new Error('Worker failed');
|
|
|
|
|
}, { scope: 'worker' }]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('pass', async ({failure}) => {
|
|
|
|
|
expect(true).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
expect(result.report.errors[0].message).toContain('Worker failed');
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
2021-09-28 20:56:50 +03:00
|
|
|
|
test('should handle worker tear down fixture error after failed test', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-09-28 20:56:50 +03:00
|
|
|
|
failure: [async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
throw new Error('Worker failed');
|
|
|
|
|
}, { scope: 'worker' }]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('timeout', async ({failure}) => {
|
|
|
|
|
await new Promise(f => setTimeout(f, 2000));
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { timeout: 1000 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
2022-07-01 03:05:08 +03:00
|
|
|
|
expect(result.output).toContain('Test timeout of 1000ms exceeded.');
|
2021-09-28 20:56:50 +03:00
|
|
|
|
expect(result.output).toContain('Worker failed');
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('should throw when using non-defined super worker fixture', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: [async ({ foo }, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
}, { scope: 'worker' }]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('works', async ({foo}) => {});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
expect(result.output).toContain(`Fixture "foo" references itself, but does not have a base implementation.`);
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain('a.spec.ts:3');
|
|
|
|
|
expect(result.output).toContain('const test = base.extend');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should throw when defining test fixture with the same name as a worker fixture', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'e.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test1 = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: [async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
}, { scope: 'worker' }]
|
|
|
|
|
});
|
|
|
|
|
const test2 = test1.extend({
|
|
|
|
|
foo: [async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
}, { scope: 'test' }]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test2('works', async ({foo}) => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain(`Fixture "foo" has already been registered as a { scope: 'worker' } fixture defined in e.spec.ts:3:26.`);
|
|
|
|
|
expect(result.output).toContain(`e.spec.ts:8`);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.output).toContain('const test2 = test1.extend');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should throw when defining worker fixture with the same name as a test fixture', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'e.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test1 = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: [async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
}, { scope: 'test' }]
|
|
|
|
|
});
|
|
|
|
|
const test2 = test1.extend({
|
|
|
|
|
foo: [async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
}, { scope: 'worker' }]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test2('works', async ({foo}) => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain(`Fixture "foo" has already been registered as a { scope: 'test' } fixture defined in e.spec.ts:3:26.`);
|
|
|
|
|
expect(result.output).toContain(`e.spec.ts:8`);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.output).toContain('const test2 = test1.extend');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should throw when worker fixture depends on a test fixture', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'f.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: [async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
}, { scope: 'test' }],
|
|
|
|
|
|
|
|
|
|
bar: [async ({ foo }, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
}, { scope: 'worker' }],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('works', async ({bar}) => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain('worker fixture "bar" cannot depend on a test fixture "foo" defined in f.spec.ts:3:25.');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should define the same fixture in two files', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test1 = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: [async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
}, { scope: 'worker' }]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test1('works', async ({foo}) => {});
|
|
|
|
|
`,
|
|
|
|
|
'b.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test2 = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: [async ({}, runTest) => {
|
|
|
|
|
await runTest();
|
|
|
|
|
}, { scope: 'worker' }]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test2('works', async ({foo}) => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should detect fixture dependency cycle', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'x.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
good1: async ({}, run) => run(),
|
|
|
|
|
foo: async ({bar}, run) => run(),
|
|
|
|
|
bar: async ({baz}, run) => run(),
|
|
|
|
|
good2: async ({good1}, run) => run(),
|
|
|
|
|
baz: async ({qux}, run) => run(),
|
|
|
|
|
qux: async ({foo}, run) => run(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('works', async ({foo}) => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
2022-12-23 04:31:02 +03:00
|
|
|
|
expect(result.output).toContain('Fixtures "bar" -> "baz" -> "qux" -> "foo" -> "bar" form a dependency cycle:');
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain('x.spec.ts:3:25 -> x.spec.ts:3:25 -> x.spec.ts:3:25 -> x.spec.ts:3:25');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should not reuse fixtures from one file in another one', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({ foo: ({}, run) => run() });
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('test1', async ({}) => {});
|
|
|
|
|
`,
|
|
|
|
|
'b.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('test1', async ({}) => {});
|
|
|
|
|
test('test2', async ({foo}) => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.output).toContain('Test has unknown parameter "foo".');
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain('b.spec.ts:4');
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.output).toContain(`test('test2', async ({foo}) => {})`);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should throw for cycle in two overrides', 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 test1 = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: async ({}, run) => await run('foo'),
|
|
|
|
|
bar: async ({}, run) => await run('bar'),
|
|
|
|
|
});
|
|
|
|
|
const test2 = test1.extend({
|
|
|
|
|
foo: async ({ foo, bar }, run) => await run(foo + '-' + bar),
|
|
|
|
|
});
|
|
|
|
|
const test3 = test2.extend({
|
|
|
|
|
bar: async ({ bar, foo }, run) => await run(bar + '-' + foo),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test3('test', async ({foo, bar}) => {
|
|
|
|
|
expect(1).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
2022-12-23 04:31:02 +03:00
|
|
|
|
expect(result.output).toContain('Fixtures "bar" -> "foo" -> "bar" form a dependency cycle:');
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain('a.test.js:10:27 -> a.test.js:7:27');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should throw when overridden worker fixture depends on a test fixture', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'f.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test1 = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: async ({}, run) => await run('foo'),
|
|
|
|
|
bar: [ async ({}, run) => await run('bar'), { scope: 'worker' } ],
|
|
|
|
|
});
|
|
|
|
|
const test2 = test1.extend({
|
|
|
|
|
bar: async ({ foo }, run) => await run(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test2('works', async ({bar}) => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain('worker fixture "bar" cannot depend on a test fixture "foo" defined in f.spec.ts:3:26.');
|
|
|
|
|
expect(result.output).toContain('f.spec.ts:7');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should throw for unknown fixture parameter', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'f.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: async ({ bar }, run) => await run('foo'),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('works', async ({ foo }) => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.output).toContain('Fixture "foo" has unknown parameter "bar".');
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain('f.spec.ts:3');
|
|
|
|
|
expect(result.output).toContain('const test = base.extend');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should throw when calling runTest twice', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'f.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
foo: async ({}, run) => {
|
|
|
|
|
await run();
|
|
|
|
|
await run();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('works', async ({foo}) => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.results[0].error.message).toBe('Cannot provide fixture value for the second time');
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should print nice error message for problematic fixtures', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'x.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
bad: [ undefined, { get scope() { throw new Error('oh my!') } } ],
|
|
|
|
|
});
|
|
|
|
|
test('works', async ({foo}) => {});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.output).toContain('oh my!');
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain('x.spec.ts:4:49');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should exit with timeout when fixture causes an exception in the test', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
throwAfterTimeout: async ({}, use) => {
|
|
|
|
|
let callback;
|
|
|
|
|
const promise = new Promise((f, r) => callback = r);
|
|
|
|
|
await use(promise);
|
|
|
|
|
callback(new Error('BAD'));
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
test('times out and throws', async ({ throwAfterTimeout }) => {
|
|
|
|
|
await throwAfterTimeout;
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { timeout: 500 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2022-07-01 03:05:08 +03:00
|
|
|
|
expect(result.output).toContain('Test timeout of 500ms exceeded.');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
2021-08-05 07:11:02 +03:00
|
|
|
|
|
|
|
|
|
test('should error for unsupported scope', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-08-05 07:11:02 +03:00
|
|
|
|
failure: [async ({}, use) => {
|
|
|
|
|
await use();
|
|
|
|
|
}, { scope: 'foo' }]
|
|
|
|
|
});
|
|
|
|
|
test('skipped', async ({failure}) => {
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
2022-12-23 04:31:02 +03:00
|
|
|
|
expect(result.output).toContain(`Fixture "failure" has unknown { scope: 'foo' }`);
|
2021-08-05 07:11:02 +03:00
|
|
|
|
});
|
2021-12-21 03:19:21 +03:00
|
|
|
|
|
|
|
|
|
test('should give enough time for fixture teardown', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-12-21 03:19:21 +03:00
|
|
|
|
fixture: async ({ }, use) => {
|
|
|
|
|
await use();
|
|
|
|
|
console.log('\\n%%teardown start');
|
2023-05-03 03:40:10 +03:00
|
|
|
|
await new Promise(f => setTimeout(f, 2000));
|
2021-12-21 03:19:21 +03:00
|
|
|
|
console.log('\\n%%teardown finished');
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
test('fast enough but close', async ({ fixture }) => {
|
2023-05-03 03:40:10 +03:00
|
|
|
|
test.setTimeout(3000);
|
|
|
|
|
await new Promise(f => setTimeout(f, 2000));
|
2021-12-21 03:19:21 +03:00
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2023-05-03 03:40:10 +03:00
|
|
|
|
expect(result.output).toContain('Test finished within timeout of 3000ms, but tearing down "fixture" ran out of time.');
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'teardown start',
|
|
|
|
|
'teardown finished',
|
2021-12-21 03:19:21 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should not teardown when setup times out', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2021-12-21 03:19:21 +03:00
|
|
|
|
fixture: async ({ }, use) => {
|
|
|
|
|
await new Promise(f => setTimeout(f, 1500));
|
|
|
|
|
await use();
|
|
|
|
|
console.log('\\n%%teardown');
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
test('fast enough but close', async ({ fixture }) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { timeout: 1000 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2022-07-01 03:05:08 +03:00
|
|
|
|
expect(result.output).toContain('Test timeout of 1000ms exceeded while setting up "fixture".');
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
2021-12-21 03:19:21 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
2022-01-13 21:38:47 +03:00
|
|
|
|
|
|
|
|
|
test('should not report fixture teardown error twice', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2022-01-13 21:38:47 +03:00
|
|
|
|
fixture: async ({ }, use) => {
|
|
|
|
|
await use();
|
|
|
|
|
throw new Error('Oh my error');
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
test('good', async ({ fixture }) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'list' });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.output).toContain('Error: Oh my error');
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.output).toContain(`throw new Error('Oh my error')`);
|
|
|
|
|
expect(countTimes(result.output, 'Oh my error')).toBe(2);
|
2022-03-09 03:35:14 +03:00
|
|
|
|
});
|
|
|
|
|
|
2023-07-25 00:09:20 +03:00
|
|
|
|
test('should not report fixture teardown timeout twice', async ({ runInlineTest }) => {
|
2022-03-09 03:35:14 +03:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2022-03-09 03:35:14 +03:00
|
|
|
|
fixture: async ({ }, use) => {
|
|
|
|
|
await use();
|
|
|
|
|
await new Promise(() => {});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
test('good', async ({ fixture }) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'list', timeout: 1000 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2023-03-11 00:45:47 +03:00
|
|
|
|
expect(result.output).toContain('Test finished within timeout of 1000ms, but tearing down "fixture" ran out of time.');
|
2023-07-25 00:09:20 +03:00
|
|
|
|
expect(result.output).not.toContain('base.extend'); // Should not point to the location.
|
|
|
|
|
// TODO: this should be "not.toContain" actually.
|
2022-07-15 23:05:48 +03:00
|
|
|
|
expect(result.output).toContain('Worker teardown timeout of 1000ms exceeded while tearing down "fixture".');
|
2022-01-13 21:38:47 +03:00
|
|
|
|
});
|
2022-02-16 05:05:20 +03:00
|
|
|
|
|
|
|
|
|
test('should handle fixture teardown error after test timeout and continue', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2022-02-16 05:05:20 +03:00
|
|
|
|
fixture: async ({ }, use) => {
|
|
|
|
|
await use();
|
|
|
|
|
throw new Error('Oh my error');
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
test('bad', async ({ fixture }) => {
|
|
|
|
|
test.setTimeout(100);
|
|
|
|
|
await new Promise(f => setTimeout(f, 500));
|
|
|
|
|
});
|
|
|
|
|
test('good', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'list', workers: '1' });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(1);
|
2022-07-01 03:05:08 +03:00
|
|
|
|
expect(result.output).toContain('Test timeout of 100ms exceeded.');
|
2022-02-16 05:05:20 +03:00
|
|
|
|
expect(result.output).toContain('Error: Oh my error');
|
|
|
|
|
});
|
2022-03-29 05:58:24 +03:00
|
|
|
|
|
|
|
|
|
test('should report worker fixture teardown with debug info', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2022-03-29 05:58:24 +03:00
|
|
|
|
fixture: [ async ({ }, use) => {
|
|
|
|
|
await use();
|
|
|
|
|
await new Promise(() => {});
|
|
|
|
|
}, { scope: 'worker' } ],
|
|
|
|
|
});
|
|
|
|
|
for (let i = 0; i < 20; i++)
|
|
|
|
|
test('good' + i, async ({ fixture }) => {});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'list', timeout: 1000 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(20);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.output).toContain([
|
2022-07-29 00:46:21 +03:00
|
|
|
|
'Worker teardown timeout of 1000ms exceeded while tearing down "fixture".',
|
|
|
|
|
'',
|
|
|
|
|
'Failed worker ran 20 tests, last 10 tests were:',
|
2023-02-15 06:20:56 +03:00
|
|
|
|
'a.spec.ts:10:9 › good10',
|
|
|
|
|
'a.spec.ts:10:9 › good11',
|
|
|
|
|
'a.spec.ts:10:9 › good12',
|
|
|
|
|
'a.spec.ts:10:9 › good13',
|
|
|
|
|
'a.spec.ts:10:9 › good14',
|
|
|
|
|
'a.spec.ts:10:9 › good15',
|
|
|
|
|
'a.spec.ts:10:9 › good16',
|
|
|
|
|
'a.spec.ts:10:9 › good17',
|
|
|
|
|
'a.spec.ts:10:9 › good18',
|
|
|
|
|
'a.spec.ts:10:9 › good19',
|
2022-03-29 05:58:24 +03:00
|
|
|
|
].join('\n'));
|
|
|
|
|
});
|
2022-07-06 03:15:28 +03:00
|
|
|
|
|
|
|
|
|
test('should not run user fn when require fixture has failed', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({
|
2022-07-06 03:15:28 +03:00
|
|
|
|
foo: [ async ({ }, use) => {
|
|
|
|
|
console.log('\\n%%foo');
|
|
|
|
|
throw new Error('A test error!');
|
|
|
|
|
await use();
|
|
|
|
|
}, { scope: 'test' } ],
|
|
|
|
|
bar: [ async ({ foo }, use) => {
|
|
|
|
|
console.log('\\n%%bar-' + foo);
|
|
|
|
|
await use();
|
|
|
|
|
}, { scope: 'test' } ],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.skip(({ foo }) => {
|
|
|
|
|
console.log('\\n%%skip-' + foo);
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.beforeEach(({ foo }) => {
|
|
|
|
|
console.log('\\n%%beforeEach1-' + foo);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.beforeEach(({ foo }) => {
|
|
|
|
|
console.log('\\n%%beforeEach2-' + foo);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.beforeEach(({ bar }) => {
|
|
|
|
|
console.log('\\n%%beforeEach3-' + bar);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.afterEach(({ foo }) => {
|
|
|
|
|
console.log('\\n%%afterEach1-' + foo);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.afterEach(({ bar }) => {
|
|
|
|
|
console.log('\\n%%afterEach2-' + bar);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should not run', async ({ bar }) => {
|
|
|
|
|
console.log('\\n%%test-' + bar);
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
|
'foo',
|
2022-07-06 03:15:28 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
2022-07-26 18:53:32 +03:00
|
|
|
|
|
|
|
|
|
test('should provide helpful error message when digests do not match', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'helper.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base } from '@playwright/test';
|
|
|
|
|
export * from '@playwright/test';
|
|
|
|
|
export const test = base.extend({
|
2022-07-26 18:53:32 +03:00
|
|
|
|
foo: [ async ({}, use) => use(), { scope: 'worker' } ],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.use({ foo: 'foo' });
|
|
|
|
|
`,
|
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from './helper';
|
2022-07-26 18:53:32 +03:00
|
|
|
|
|
|
|
|
|
test('test-a', ({ foo }) => {
|
|
|
|
|
expect(foo).toBe('foo');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'b.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from './helper';
|
2022-07-26 18:53:32 +03:00
|
|
|
|
|
|
|
|
|
test('test-b', ({ foo }) => {
|
|
|
|
|
expect(foo).toBe('foo');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'c.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from './helper';
|
2022-07-26 18:53:32 +03:00
|
|
|
|
|
|
|
|
|
test('test-c', ({ foo }) => {
|
|
|
|
|
expect(foo).toBe('foo');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { workers: 1 });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2023-02-08 02:11:44 +03:00
|
|
|
|
expect(result.output).toContain('Playwright detected inconsistent test.use() options.');
|
2022-07-26 18:53:32 +03:00
|
|
|
|
});
|