Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when given unsupported product name. #5845

Merged
merged 2 commits into from May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -82,6 +82,7 @@
"pixelmatch": "^4.0.2",
"pngjs": "^5.0.0",
"prettier": "^2.0.5",
"sinon": "^9.0.2",
"text-diff": "^1.0.1",
"typescript": "3.8.3"
},
Expand Down
9 changes: 9 additions & 0 deletions src/Launcher.ts
Expand Up @@ -1027,6 +1027,15 @@ function Launcher(
);
case 'chrome':
default:
if (typeof product !== 'undefined' && product !== 'chrome') {
/* The user gave us an incorrect product name
* we'll default to launching Chrome, but log to the console
* to let the user know (they've probably typoed).
*/
console.warn(
`Warning: unknown product name ${product}. Falling back to chrome.`
);
}
return new ChromeLauncher(
projectRoot,
preferredRevision,
Expand Down
14 changes: 14 additions & 0 deletions test/launcher.spec.js
Expand Up @@ -16,6 +16,7 @@
const fs = require('fs');
const os = require('os');
const path = require('path');
const sinon = require('sinon');
const { helper } = require('../lib/helper');
const rmAsync = helper.promisify(require('rimraf'));
const mkdtempAsync = helper.promisify(fs.mkdtemp);
Expand Down Expand Up @@ -444,6 +445,19 @@ describe('Launcher specs', function () {
expect(userAgent).toContain('Chrome');
});

it('falls back to launching chrome if there is an unknown product but logs a warning', async () => {
const { puppeteer } = getTestState();
const consoleStub = sinon.stub(console, 'warn');
const browser = await puppeteer.launch({ product: 'SO_NOT_A_PRODUCT' });
const userAgent = await browser.userAgent();
await browser.close();
expect(userAgent).toContain('Chrome');
expect(consoleStub.callCount).toEqual(1);
expect(consoleStub.firstCall.args).toEqual([
'Warning: unknown product name SO_NOT_A_PRODUCT. Falling back to chrome.',
]);
});

/* We think there's a bug in the FF Windows launcher, or some
* combo of that plus it running on CI, but we're deferring fixing
* this so we can get Windows CI stable and then dig into this
Expand Down
5 changes: 5 additions & 0 deletions test/mocha-utils.js
Expand Up @@ -18,6 +18,7 @@ const { TestServer } = require('../utils/testserver/index');
const path = require('path');
const fs = require('fs');
const os = require('os');
const sinon = require('sinon');
const puppeteer = require('../');
const utils = require('./utils');
const { trackCoverage } = require('./coverage-utils');
Expand Down Expand Up @@ -169,3 +170,7 @@ after(async () => {
await state.httpsServer.stop();
state.httpsServer = null;
});

afterEach(() => {
sinon.restore();
});