fix(test runner): do not override browserName when using without --browser (#7806)

This commit is contained in:
Dmitry Gozman 2021-07-23 09:04:20 -07:00 committed by GitHub
parent 827fb80465
commit bf6482a58d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 15 deletions

View File

@ -84,16 +84,18 @@ export function addTestCommand(program: commander.CommanderStatic) {
async function runTests(args: string[], opts: { [key: string]: any }) {
await startProfiling();
const browserOpt = opts.browser ? opts.browser.toLowerCase() : 'chromium';
if (!['all', 'chromium', 'firefox', 'webkit'].includes(browserOpt))
throw new Error(`Unsupported browser "${opts.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
const browserNames = browserOpt === 'all' ? ['chromium', 'firefox', 'webkit'] : [browserOpt];
defaultConfig.projects = browserNames.map(browserName => {
return {
name: browserName,
use: { browserName },
};
});
if (opts.browser) {
const browserOpt = opts.browser.toLowerCase();
if (!['all', 'chromium', 'firefox', 'webkit'].includes(browserOpt))
throw new Error(`Unsupported browser "${opts.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
const browserNames = browserOpt === 'all' ? ['chromium', 'firefox', 'webkit'] : [browserOpt];
defaultConfig.projects = browserNames.map(browserName => {
return {
name: browserName,
use: { browserName },
};
});
}
const overrides = overridesFromOptions(opts);
if (opts.headed)

View File

@ -121,6 +121,46 @@ test('should complain with projects and --browser', async ({ runInlineTest }) =>
expect(result.output).toContain('Cannot use --browser option when configuration file defines projects');
});
test('should not override use:browserName without projects', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { browserName: 'webkit' } };
`,
'a.test.ts': `
const { test } = pwt;
test('pass', async ({ page, browserName }) => {
console.log('\\n%%browser=' + browserName);
});
`,
}, { workers: 1 });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
expect(result.output.split('\n').filter(line => line.startsWith('%%')).sort()).toEqual([
'%%browser=webkit',
]);
});
test('should override use:browserName with --browser', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { browserName: 'webkit' } };
`,
'a.test.ts': `
const { test } = pwt;
test('pass', async ({ page, browserName }) => {
console.log('\\n%%browser=' + browserName);
});
`,
}, { browser: 'firefox', workers: 1 });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
expect(result.output.split('\n').filter(line => line.startsWith('%%')).sort()).toEqual([
'%%browser=firefox',
]);
});
test('should report error and pending operations on timeout', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'a.test.ts': `
@ -148,7 +188,7 @@ test('should report error and pending operations on timeout', async ({ runInline
test('should work with screenshot: only-on-failure', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { screenshot: 'only-on-failure' } };
module.exports = { use: { screenshot: 'only-on-failure' }, name: 'chromium' };
`,
'a.test.ts': `
const { test } = pwt;
@ -175,7 +215,7 @@ test('should work with screenshot: only-on-failure', async ({ runInlineTest }, t
test('should work with video: retain-on-failure', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { video: 'retain-on-failure' } };
module.exports = { use: { video: 'retain-on-failure' }, name: 'chromium' };
`,
'a.test.ts': `
const { test } = pwt;
@ -207,7 +247,7 @@ test('should work with video: retain-on-failure', async ({ runInlineTest }, test
test('should work with video: on-first-retry', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { video: 'on-first-retry' }, retries: 1 };
module.exports = { use: { video: 'on-first-retry' }, retries: 1, name: 'chromium' };
`,
'a.test.ts': `
const { test } = pwt;
@ -238,11 +278,12 @@ test('should work with video: on-first-retry', async ({ runInlineTest }, testInf
expect(videoFailRetry).toBeTruthy();
});
test('should work with video size', async ({ runInlineTest, browserName }, testInfo) => {
test('should work with video size', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'playwright.config.js': `
module.exports = {
use: { video: { mode: 'on', size: { width: 220, height: 110 } } },
name: 'chromium',
preserveOutput: 'always',
};
`,
@ -257,7 +298,7 @@ test('should work with video size', async ({ runInlineTest, browserName }, testI
}, { workers: 1 });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
const folder = testInfo.outputPath(`test-results/a-pass-${browserName}/`);
const folder = testInfo.outputPath(`test-results/a-pass-chromium/`);
const [file] = fs.readdirSync(folder);
const videoPlayer = new VideoPlayer(path.join(folder, file));
expect(videoPlayer.videoWidth).toBe(220);

View File

@ -22,6 +22,7 @@ test('should work and remove non-failures', async ({ runInlineTest }, testInfo)
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = {
name: 'chromium',
preserveOutput: 'failures-only',
testDir: 'dir',
};