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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
import { test, expect } from './playwright-test-fixtures';
|
|
|
|
|
|
|
|
|
|
test('should be able to define config', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { timeout: 12345 };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('pass', async ({}, testInfo) => {
|
|
|
|
|
expect(testInfo.timeout).toBe(12345);
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should prioritize project timeout', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { timeout: 500, projects: [{ timeout: 10000}, {}] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('pass', async ({}, testInfo) => {
|
|
|
|
|
await new Promise(f => setTimeout(f, 1500));
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should prioritize command line timeout over project timeout', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { projects: [{ timeout: 10000}] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('pass', async ({}, testInfo) => {
|
|
|
|
|
await new Promise(f => setTimeout(f, 1500));
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { 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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should read config from --config, resolve relative testDir', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'my.config.ts': `
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
module.exports = {
|
|
|
|
|
testDir: 'dir',
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('ignored', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'dir/b.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('run', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { config: 'my.config.ts' });
|
|
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
expect(result.report.suites.length).toBe(1);
|
|
|
|
|
expect(result.report.suites[0].file).toBe('b.test.ts');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should default testDir to the config file', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'dir/my.config.ts': `
|
|
|
|
|
module.exports = {};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('ignored', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'dir/b.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('run', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { config: path.join('dir', 'my.config.ts') });
|
|
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
expect(result.report.suites.length).toBe(1);
|
|
|
|
|
expect(result.report.suites[0].file).toBe('b.test.ts');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should be able to set reporters', async ({ runInlineTest }, testInfo) => {
|
|
|
|
|
const reportFile = testInfo.outputPath('my-report.json');
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = {
|
|
|
|
|
reporter: [
|
|
|
|
|
['json', { outputFile: ${JSON.stringify(reportFile)} }],
|
|
|
|
|
['list'],
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('pass', async () => {
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { reporter: '' });
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
const report = JSON.parse(fs.readFileSync(reportFile).toString());
|
|
|
|
|
expect(report.suites[0].file).toBe('a.test.ts');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should support different testDirs', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
module.exports = { projects: [
|
|
|
|
|
{ testDir: __dirname },
|
|
|
|
|
{ testDir: 'dir' },
|
|
|
|
|
] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('runs once', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'dir/b.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('runs twice', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(3);
|
|
|
|
|
|
|
|
|
|
expect(result.report.suites[0].specs[0].tests.length).toBe(1);
|
|
|
|
|
expect(result.report.suites[0].specs[0].title).toBe('runs once');
|
|
|
|
|
|
|
|
|
|
expect(result.report.suites[1].specs[0].tests.length).toBe(2);
|
|
|
|
|
expect(result.report.suites[1].specs[0].title).toBe('runs twice');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should allow root testDir and use it for relative paths', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'config/config.ts': `
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
module.exports = {
|
|
|
|
|
testDir: path.join(__dirname, '..'),
|
|
|
|
|
projects: [{ testDir: path.join(__dirname, '..', 'dir') }]
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('fails', async ({}, testInfo) => {
|
|
|
|
|
expect(1 + 1).toBe(3);
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'dir/a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('fails', async ({}, testInfo) => {
|
|
|
|
|
expect(1 + 1).toBe(3);
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { config: path.join('config', 'config.ts') });
|
|
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
|
expect(result.skipped).toBe(0);
|
|
|
|
|
expect(result.failed).toBe(1);
|
2023-02-15 06:20:56 +03:00
|
|
|
|
expect(result.output).toContain(`1) ${path.join('dir', 'a.test.ts')}:3:11 › fails`);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should throw when test() is called in config file', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
|
test('hey', () => {});
|
2021-06-07 03:09:53 +03:00
|
|
|
|
module.exports = {};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('test', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
});
|
2022-02-19 05:25:18 +03:00
|
|
|
|
expect(result.output).toContain('Playwright Test did not expect test() to be called here');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should filter by project, case-insensitive', async ({ runInlineTest }) => {
|
2024-02-03 01:05:20 +03:00
|
|
|
|
const { passed, failed, outputLines, skipped } = await runInlineTest({
|
2021-06-07 03:09:53 +03:00
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { projects: [
|
|
|
|
|
{ name: 'suite1' },
|
|
|
|
|
{ name: 'suite2' },
|
|
|
|
|
] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2024-02-03 01:05:20 +03:00
|
|
|
|
import { test } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('pass', async ({}, testInfo) => {
|
2024-02-03 01:05:20 +03:00
|
|
|
|
console.log('%%' + test.info().project.name);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { project: 'SUite2' });
|
|
|
|
|
expect(passed).toBe(1);
|
|
|
|
|
expect(failed).toBe(0);
|
|
|
|
|
expect(skipped).toBe(0);
|
2024-02-03 01:05:20 +03:00
|
|
|
|
expect(new Set(outputLines)).toEqual(new Set([
|
|
|
|
|
'suite2',
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-17 06:18:00 +03:00
|
|
|
|
test('should filter by project wildcard', async ({ runInlineTest }) => {
|
2024-02-03 01:05:20 +03:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.js': `
|
|
|
|
|
module.exports = {
|
|
|
|
|
projects: [
|
2024-02-10 22:19:00 +03:00
|
|
|
|
{ name: 'project-name' },
|
|
|
|
|
{ name: 'foobar' }
|
2024-02-03 01:05:20 +03:00
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = require('@playwright/test');
|
|
|
|
|
test('one', async ({}) => {
|
|
|
|
|
console.log('%%' + test.info().project.name);
|
|
|
|
|
}); `
|
2024-02-17 06:18:00 +03:00
|
|
|
|
}, { '--project': '*oj*t-Na*e' });
|
2024-02-03 01:05:20 +03:00
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.output).toContain('Running 1 test using 1 worker');
|
|
|
|
|
expect(new Set(result.outputLines)).toEqual(new Set([
|
|
|
|
|
'project-name',
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-17 06:18:00 +03:00
|
|
|
|
test('should print nice error when the project wildcard does not match anything', async ({ runInlineTest }) => {
|
2024-02-10 22:19:00 +03:00
|
|
|
|
const { output, exitCode } = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { projects: [
|
|
|
|
|
{ name: 'suite1' },
|
|
|
|
|
{ name: 'suite2' },
|
|
|
|
|
] };
|
2024-02-03 01:05:20 +03:00
|
|
|
|
`,
|
2024-02-10 22:19:00 +03:00
|
|
|
|
'a.test.ts': `
|
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
|
test('pass', async ({}, testInfo) => {
|
|
|
|
|
console.log(testInfo.project.name);
|
|
|
|
|
});
|
|
|
|
|
`
|
2024-02-17 06:18:00 +03:00
|
|
|
|
}, { '--project': ['not*found'] });
|
2024-02-10 22:19:00 +03:00
|
|
|
|
expect(exitCode).toBe(1);
|
2024-02-17 06:18:00 +03:00
|
|
|
|
expect(output).toContain('Error: No projects matched. Available projects: "suite1", "suite2"');
|
2024-02-10 22:19:00 +03:00
|
|
|
|
});
|
|
|
|
|
|
2024-02-17 06:18:00 +03:00
|
|
|
|
test('should filter by project wildcard and exact name', async ({ runInlineTest }) => {
|
2024-02-03 01:05:20 +03:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.js': `
|
|
|
|
|
module.exports = {
|
|
|
|
|
projects: [
|
2024-02-17 06:18:00 +03:00
|
|
|
|
{ name: 'first' },
|
2024-02-03 01:05:20 +03:00
|
|
|
|
{ name: 'fooBar' },
|
2024-02-17 06:18:00 +03:00
|
|
|
|
{ name: 'foobarBaz' },
|
|
|
|
|
{ name: 'prefix' },
|
|
|
|
|
{ name: 'prefixEnd' },
|
2024-02-03 01:05:20 +03:00
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = require('@playwright/test');
|
|
|
|
|
test('one', async ({}) => {
|
|
|
|
|
console.log('%%' + test.info().project.name);
|
|
|
|
|
}); `
|
2024-02-17 06:18:00 +03:00
|
|
|
|
}, { '--project': ['first', '*bar', 'pref*x'] });
|
2024-02-03 01:05:20 +03:00
|
|
|
|
expect(result.exitCode).toBe(0);
|
2024-02-17 06:18:00 +03:00
|
|
|
|
expect(new Set(result.outputLines)).toEqual(new Set(['first', 'fooBar', 'prefix']));
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should print nice error when project is unknown', async ({ runInlineTest }) => {
|
|
|
|
|
const { output, exitCode } = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { projects: [
|
|
|
|
|
{ name: 'suite1' },
|
|
|
|
|
{ name: 'suite2' },
|
|
|
|
|
] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2024-02-03 01:05:20 +03:00
|
|
|
|
test('pass', async ({}, testInfo) => {});
|
2021-06-07 03:09:53 +03:00
|
|
|
|
`
|
|
|
|
|
}, { project: 'suite3' });
|
|
|
|
|
expect(exitCode).toBe(1);
|
2024-02-10 22:19:00 +03:00
|
|
|
|
expect(output).toContain('Project(s) "suite3" not found. Available projects: "suite1", "suite2"');
|
2021-09-02 19:29:55 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should filter by project list, case-insensitive', async ({ runInlineTest }) => {
|
2024-02-03 01:05:20 +03:00
|
|
|
|
const { passed, failed, outputLines, skipped } = await runInlineTest({
|
2021-09-02 19:29:55 +03:00
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { projects: [
|
|
|
|
|
{ name: 'suite1' },
|
|
|
|
|
{ name: 'suite2' },
|
|
|
|
|
{ name: 'suite3' },
|
|
|
|
|
{ name: 'suite4' },
|
|
|
|
|
] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-09-02 19:29:55 +03:00
|
|
|
|
test('pass', async ({}, testInfo) => {
|
2024-02-03 01:05:20 +03:00
|
|
|
|
console.log('%%' + test.info().project.name);
|
2021-09-02 19:29:55 +03:00
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { project: ['SUite2', 'Suite3'] });
|
|
|
|
|
expect(passed).toBe(2);
|
|
|
|
|
expect(failed).toBe(0);
|
|
|
|
|
expect(skipped).toBe(0);
|
2024-02-03 01:05:20 +03:00
|
|
|
|
expect(new Set(outputLines)).toEqual(new Set(['suite3', 'suite2']));
|
2021-09-02 19:29:55 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should filter when duplicate project names exist', async ({ runInlineTest }) => {
|
2024-02-03 01:05:20 +03:00
|
|
|
|
const { passed, failed, outputLines, skipped } = await runInlineTest({
|
2021-09-02 19:29:55 +03:00
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { projects: [
|
|
|
|
|
{ name: 'suite1' },
|
|
|
|
|
{ name: 'suite2' },
|
|
|
|
|
{ name: 'suite1' },
|
|
|
|
|
{ name: 'suite4' },
|
|
|
|
|
] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-09-02 19:29:55 +03:00
|
|
|
|
test('pass', async ({}, testInfo) => {
|
2024-02-03 01:05:20 +03:00
|
|
|
|
console.log('%%' + test.info().project.name);
|
2021-09-02 19:29:55 +03:00
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { project: ['suite1', 'sUIte4'] });
|
|
|
|
|
expect(passed).toBe(3);
|
|
|
|
|
expect(failed).toBe(0);
|
|
|
|
|
expect(skipped).toBe(0);
|
2024-02-03 01:05:20 +03:00
|
|
|
|
expect(new Set(outputLines)).toEqual(new Set(['suite1', 'suite1', 'suite4']));
|
2021-09-02 19:29:55 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should print nice error when some of the projects are unknown', async ({ runInlineTest }) => {
|
|
|
|
|
const { output, exitCode } = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { projects: [
|
|
|
|
|
{ name: 'suite1' },
|
|
|
|
|
{ name: 'suite2' },
|
|
|
|
|
] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-09-02 19:29:55 +03:00
|
|
|
|
test('pass', async ({}, testInfo) => {
|
|
|
|
|
console.log(testInfo.project.name);
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { project: ['suitE1', 'suIte3', 'SUite4'] });
|
|
|
|
|
expect(exitCode).toBe(1);
|
2024-02-10 22:19:00 +03:00
|
|
|
|
expect(output).toContain('Project(s) "suIte3", "SUite4" not found. Available projects: "suite1", "suite2"');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should work without config file', async ({ runInlineTest }) => {
|
|
|
|
|
const { exitCode, passed, failed, skipped } = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
throw new Error('This file should not be required');
|
|
|
|
|
`,
|
|
|
|
|
'dir/a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('pass', async ({}) => {
|
|
|
|
|
test.expect(1 + 1).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { config: 'dir' });
|
|
|
|
|
expect(exitCode).toBe(0);
|
|
|
|
|
expect(passed).toBe(1);
|
|
|
|
|
expect(failed).toBe(0);
|
|
|
|
|
expect(skipped).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
|
2023-01-30 11:53:28 +03:00
|
|
|
|
test('should inherit use options in projects', async ({ runInlineTest }) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = {
|
|
|
|
|
use: { foo: 'config' },
|
|
|
|
|
projects: [{
|
|
|
|
|
use: { bar: 'project' },
|
|
|
|
|
}]
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
|
const test = base.extend({ foo: ['', {option:true}], bar: ['', {option: true}] });
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('pass', async ({ foo, bar }, testInfo) => {
|
|
|
|
|
test.expect(foo).toBe('config');
|
|
|
|
|
test.expect(bar).toBe('project');
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
2022-09-01 15:34:36 +03:00
|
|
|
|
test('should support ignoreSnapshots config option', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = {
|
|
|
|
|
ignoreSnapshots: true,
|
2024-04-23 02:16:38 +03:00
|
|
|
|
projects: [
|
|
|
|
|
{ name: 'p1' },
|
|
|
|
|
{ name: 'p2', ignoreSnapshots: false },
|
|
|
|
|
]
|
2022-09-01 15:34:36 +03:00
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-09-01 15:34:36 +03:00
|
|
|
|
test('pass', async ({}, testInfo) => {
|
2024-04-23 02:16:38 +03:00
|
|
|
|
testInfo.snapshotSuffix = '';
|
|
|
|
|
expect(testInfo.project.name).toMatchSnapshot();
|
2022-09-01 15:34:36 +03:00
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-23 02:16:38 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
2022-09-01 15:34:36 +03:00
|
|
|
|
expect(result.passed).toBe(1);
|
2024-04-23 02:16:38 +03:00
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
expect(result.output).not.toContain(`pass-1-p1.txt, writing actual.`);
|
|
|
|
|
expect(result.output).toContain(`pass-1-p2.txt, writing actual.`);
|
2022-09-01 15:34:36 +03:00
|
|
|
|
});
|
|
|
|
|
|
2022-09-21 21:17:36 +03:00
|
|
|
|
test('should validate workers option set to percent', async ({ runInlineTest }, testInfo) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = {
|
|
|
|
|
workers: '50%'
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-09-21 21:17:36 +03:00
|
|
|
|
test('pass', async () => {
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should throw when workers option is invalid', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = {
|
|
|
|
|
workers: ''
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2022-09-21 21:17:36 +03:00
|
|
|
|
test('pass', async () => {
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.output).toContain('config.workers must be a number or percentage');
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('should work with undefined values and base', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = {
|
|
|
|
|
updateSnapshots: undefined,
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('pass', async ({}, testInfo) => {
|
2021-06-16 17:51:54 +03:00
|
|
|
|
expect(testInfo.config.updateSnapshots).toBe('missing');
|
2021-06-07 03:09:53 +03:00
|
|
|
|
});
|
|
|
|
|
`
|
2022-02-24 23:39:28 +03:00
|
|
|
|
});
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
});
|
2022-07-25 11:39:06 +03:00
|
|
|
|
|
|
|
|
|
test('should have correct types for the config', async ({ runTSC }) => {
|
|
|
|
|
const result = await runTSC({
|
|
|
|
|
'playwright.config.ts': `
|
2023-01-13 00:12:02 +03:00
|
|
|
|
import { defineConfig } from '@playwright/test';
|
2022-07-25 11:39:06 +03:00
|
|
|
|
|
2023-01-13 00:12:02 +03:00
|
|
|
|
export default defineConfig({
|
2022-07-25 11:39:06 +03:00
|
|
|
|
webServer: [
|
|
|
|
|
{
|
|
|
|
|
command: 'echo 123',
|
|
|
|
|
env: { PORT: '123' },
|
|
|
|
|
port: 123,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
command: 'echo 123',
|
|
|
|
|
env: { NODE_ENV: 'test' },
|
|
|
|
|
port: 8082,
|
|
|
|
|
},
|
|
|
|
|
],
|
2022-08-01 19:01:23 +03:00
|
|
|
|
globalSetup: './globalSetup',
|
|
|
|
|
// @ts-expect-error
|
|
|
|
|
globalTeardown: null,
|
|
|
|
|
projects: [
|
|
|
|
|
{
|
|
|
|
|
name: 'project name',
|
|
|
|
|
}
|
|
|
|
|
],
|
2023-01-13 00:12:02 +03:00
|
|
|
|
});
|
2022-07-25 11:39:06 +03:00
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
});
|
2023-07-06 23:31:44 +03:00
|
|
|
|
|
|
|
|
|
test('should not allow tracesDir in launchOptions', async ({ runTSC }) => {
|
|
|
|
|
const result = await runTSC({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
import { defineConfig } from '@playwright/test';
|
|
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
|
use: {
|
|
|
|
|
launchOptions: {
|
|
|
|
|
tracesDir: 'foo',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).not.toBe(0);
|
|
|
|
|
});
|
2023-08-10 03:23:34 +03:00
|
|
|
|
|
|
|
|
|
test('should merge configs', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
import { defineConfig, expect } from '@playwright/test';
|
|
|
|
|
const baseConfig = defineConfig({
|
|
|
|
|
timeout: 10,
|
|
|
|
|
use: {
|
|
|
|
|
foo: 1,
|
|
|
|
|
},
|
|
|
|
|
expect: {
|
|
|
|
|
timeout: 11,
|
|
|
|
|
},
|
|
|
|
|
projects: [
|
|
|
|
|
{
|
|
|
|
|
name: 'A',
|
|
|
|
|
timeout: 20,
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
const derivedConfig = defineConfig(baseConfig, {
|
|
|
|
|
timeout: 30,
|
|
|
|
|
use: {
|
|
|
|
|
bar: 2,
|
|
|
|
|
},
|
|
|
|
|
expect: {
|
|
|
|
|
timeout: 12,
|
|
|
|
|
},
|
|
|
|
|
projects: [
|
|
|
|
|
{ name: 'B', timeout: 40 },
|
|
|
|
|
{ name: 'A', timeout: 50 },
|
|
|
|
|
],
|
|
|
|
|
webServer: {
|
|
|
|
|
command: 'echo 123',
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(derivedConfig).toEqual(expect.objectContaining({
|
|
|
|
|
timeout: 30,
|
|
|
|
|
use: { foo: 1, bar: 2 },
|
|
|
|
|
expect: { timeout: 12 },
|
|
|
|
|
projects: [
|
|
|
|
|
{ name: 'B', timeout: 40, use: {} },
|
|
|
|
|
{ name: 'A', timeout: 50, use: {} }
|
|
|
|
|
],
|
|
|
|
|
webServer: [{
|
|
|
|
|
command: 'echo 123',
|
|
|
|
|
}]
|
|
|
|
|
}));
|
2023-11-18 00:36:50 +03:00
|
|
|
|
|
|
|
|
|
// Should not add an empty project list.
|
|
|
|
|
expect(defineConfig({}, {}).projects).toBeUndefined();
|
2023-08-10 03:23:34 +03:00
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
|
|
|
|
import { test } from '@playwright/test';
|
|
|
|
|
test('pass', async ({}) => {});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
});
|
2023-12-13 01:01:01 +03:00
|
|
|
|
|
|
|
|
|
test('should merge ct configs', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
import { defineConfig, expect } from '@playwright/experimental-ct-react';
|
|
|
|
|
const baseConfig = defineConfig({
|
|
|
|
|
timeout: 10,
|
|
|
|
|
use: {
|
|
|
|
|
foo: 1,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const derivedConfig = defineConfig(baseConfig, {
|
|
|
|
|
grep: 'hi',
|
|
|
|
|
use: {
|
|
|
|
|
bar: 2,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Make sure ct-specific properties are preserved
|
|
|
|
|
// and config properties are merged.
|
|
|
|
|
expect(derivedConfig).toEqual(expect.objectContaining({
|
|
|
|
|
use: { foo: 1, bar: 2 },
|
|
|
|
|
grep: 'hi',
|
2024-02-13 20:34:03 +03:00
|
|
|
|
'@playwright/test': expect.objectContaining({
|
2024-04-23 02:16:38 +03:00
|
|
|
|
babelPlugins: [[expect.stringContaining('tsxTransform.js')]]
|
2024-02-13 20:34:03 +03:00
|
|
|
|
}),
|
|
|
|
|
'@playwright/experimental-ct-core': expect.objectContaining({
|
|
|
|
|
registerSourceFile: expect.stringContaining('registerSource'),
|
|
|
|
|
}),
|
2023-12-13 01:01:01 +03:00
|
|
|
|
}));
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
|
|
|
|
import { test } from '@playwright/experimental-ct-react';
|
|
|
|
|
test('pass', async ({}) => {});
|
|
|
|
|
`
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
});
|