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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { test, expect } from './playwright-test-fixtures';
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
test('basics should work', async ({ runTSC }) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
const result = await runTSC({
|
|
|
|
'a.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.describe('suite', () => {
|
|
|
|
test.beforeEach(async () => {});
|
2022-03-19 02:07:11 +03:00
|
|
|
test.afterEach(async () => {});
|
|
|
|
test.beforeAll(async () => {});
|
|
|
|
test.afterAll(async () => {});
|
2021-06-07 03:09:53 +03:00
|
|
|
test('my test', async({}, testInfo) => {
|
|
|
|
expect(testInfo.title).toBe('my test');
|
|
|
|
testInfo.annotations[0].type;
|
2022-10-28 01:53:27 +03:00
|
|
|
test.setTimeout(123);
|
2021-06-07 03:09:53 +03:00
|
|
|
});
|
2022-03-19 02:07:11 +03:00
|
|
|
test.skip('my test', async () => {});
|
|
|
|
test.fixme('my test', async () => {});
|
2021-06-07 03:09:53 +03:00
|
|
|
});
|
2022-07-06 23:54:11 +03:00
|
|
|
test.describe(() => {
|
|
|
|
test('my test', () => {});
|
|
|
|
});
|
2022-03-19 02:07:11 +03:00
|
|
|
test.describe.parallel('suite', () => {});
|
|
|
|
test.describe.parallel.only('suite', () => {});
|
|
|
|
test.describe.serial('suite', () => {});
|
|
|
|
test.describe.serial.only('suite', () => {});
|
|
|
|
test.describe.skip('suite', () => {});
|
2022-07-29 22:44:22 +03:00
|
|
|
test.describe.fixme('suite', () => {});
|
2021-08-09 23:26:33 +03:00
|
|
|
// @ts-expect-error
|
|
|
|
test.foo();
|
2022-10-28 01:53:27 +03:00
|
|
|
test.describe.configure({ mode: 'parallel' });
|
|
|
|
test.describe.configure({ retries: 3, timeout: 123 });
|
2021-06-07 03:09:53 +03:00
|
|
|
`
|
|
|
|
});
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
test('can pass sync functions everywhere', async ({ runTSC }) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
const result = await runTSC({
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
const test = base.extend<{ foo: string }>({
|
2021-06-07 03:09:53 +03:00
|
|
|
foo: ({}, use) => use('bar'),
|
|
|
|
});
|
|
|
|
test.beforeEach(({ foo }) => {});
|
|
|
|
test.afterEach(({ foo }) => {});
|
|
|
|
test.beforeAll(() => {});
|
|
|
|
test.afterAll(() => {});
|
|
|
|
test('my test', ({ foo }) => {});
|
|
|
|
`
|
|
|
|
});
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
test('can return anything from hooks', async ({ runTSC }) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
const result = await runTSC({
|
|
|
|
'a.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.beforeEach(() => '123');
|
|
|
|
test.afterEach(() => 123);
|
|
|
|
test.beforeAll(() => [123]);
|
|
|
|
test.afterAll(() => ({ a: 123 }));
|
|
|
|
`
|
|
|
|
});
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
});
|
|
|
|
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
test('test.extend options should check types', async ({ runTSC }) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
const result = await runTSC({
|
|
|
|
'helper.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
import { test as base, expect } from '@playwright/test';
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
export type Params = { foo: string };
|
2023-02-15 06:20:56 +03:00
|
|
|
export const test = base;
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
export const test1 = test.extend<Params>({ foo: [ 'foo', { option: true } ] });
|
|
|
|
export const test1b = test.extend<{ bar: string }>({ bar: [ 'bar', { option: true } ] });
|
|
|
|
export const testerror = test.extend<{ foo: string }>({
|
|
|
|
// @ts-expect-error
|
|
|
|
foo: 123
|
|
|
|
});
|
2021-06-07 03:09:53 +03:00
|
|
|
export const test2 = test1.extend<{ bar: number }>({
|
|
|
|
bar: async ({ foo }, run) => { await run(parseInt(foo)); }
|
|
|
|
});
|
|
|
|
export const test3 = test1.extend<{ bar: number }>({
|
|
|
|
// @ts-expect-error
|
|
|
|
bar: async ({ baz }, run) => { await run(42); }
|
|
|
|
});
|
2022-01-06 02:54:00 +03:00
|
|
|
// TODO: enable when _extendTest is out of experiment.
|
|
|
|
// export const test4 = test1._extendTest(test1b);
|
|
|
|
export const test4 = test1;
|
2021-06-07 03:09:53 +03:00
|
|
|
`,
|
|
|
|
'playwright.config.ts': `
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
import { Params } from './helper';
|
2023-02-15 06:20:56 +03:00
|
|
|
import { Config } from '@playwright/test';
|
|
|
|
const configs: Config<Params>[] = [];
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
|
2021-06-07 03:09:53 +03:00
|
|
|
configs.push({});
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
|
2021-06-07 03:09:53 +03:00
|
|
|
configs.push({
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
use: { foo: 'bar' },
|
|
|
|
});
|
|
|
|
|
|
|
|
configs.push({
|
|
|
|
// @ts-expect-error
|
|
|
|
use: { foo: true },
|
2021-06-07 03:09:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
configs.push({
|
|
|
|
// @ts-expect-error
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
use: { unknown: true },
|
2021-06-07 03:09:53 +03:00
|
|
|
});
|
|
|
|
module.exports = configs;
|
|
|
|
`,
|
|
|
|
'a.spec.ts': `
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
import { test, test1, test2, test3, test4 } from './helper';
|
2021-06-07 03:09:53 +03:00
|
|
|
// @ts-expect-error
|
|
|
|
test('my test', async ({ foo }) => {});
|
|
|
|
test1('my test', async ({ foo }) => {});
|
|
|
|
// @ts-expect-error
|
|
|
|
test1('my test', async ({ foo, bar }) => {});
|
|
|
|
test2('my test', async ({ foo, bar }) => {});
|
|
|
|
// @ts-expect-error
|
|
|
|
test2('my test', async ({ foo, baz }) => {});
|
2022-01-06 02:54:00 +03:00
|
|
|
// TODO: enable when _extendTest is out of experiment.
|
|
|
|
// test4('my test', async ({ foo, bar }) => {});
|
2021-06-07 03:09:53 +03:00
|
|
|
`
|
|
|
|
});
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
});
|
2022-07-30 01:16:07 +03:00
|
|
|
|
|
|
|
test('step should inherit return type from its callback ', async ({ runTSC }) => {
|
|
|
|
const result = await runTSC({
|
|
|
|
'a.spec.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
import { test, expect } from '@playwright/test';
|
2022-07-30 01:16:07 +03:00
|
|
|
test('my test', async ({ }) => {
|
|
|
|
// @ts-expect-error
|
|
|
|
const bad1: string = await test.step('my step', () => {
|
|
|
|
return 10;
|
|
|
|
});
|
|
|
|
// @ts-expect-error
|
|
|
|
const bad2: string = await test.step('my step', async () => {
|
|
|
|
return 10;
|
|
|
|
});
|
|
|
|
const good: string = await test.step('my step', async () => {
|
|
|
|
return 'foo';
|
|
|
|
});
|
|
|
|
await test.step('my step', async () => { });
|
2023-02-18 01:26:40 +03:00
|
|
|
const good2: string = await test.step('my step', () => 'foo');
|
2022-07-30 01:16:07 +03:00
|
|
|
});
|
|
|
|
`
|
|
|
|
});
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
});
|