Skip to content

Commit

Permalink
fix(test runner): do not override browserName when using without --br…
Browse files Browse the repository at this point in the history
…owser (microsoft#7806)
  • Loading branch information
dgozman committed Jul 28, 2021
1 parent 6657752 commit a494fda
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
22 changes: 12 additions & 10 deletions src/test/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 46 additions & 5 deletions tests/playwright-test/playwright.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': `
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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',
};
`,
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/playwright-test/test-output-dir.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand Down

0 comments on commit a494fda

Please sign in to comment.