diff --git a/package.json b/package.json index 74c1abc60b16e..e081e041f5116 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/Launcher.ts b/src/Launcher.ts index 49989911b5efc..be29f99719dc0 100644 --- a/src/Launcher.ts +++ b/src/Launcher.ts @@ -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, diff --git a/test/launcher.spec.js b/test/launcher.spec.js index afc645a238db2..20e694add43b2 100644 --- a/test/launcher.spec.js +++ b/test/launcher.spec.js @@ -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); @@ -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 diff --git a/test/mocha-utils.js b/test/mocha-utils.js index 4db2b7dc68ce9..0dde207fd5f80 100644 --- a/test/mocha-utils.js +++ b/test/mocha-utils.js @@ -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'); @@ -169,3 +170,7 @@ after(async () => { await state.httpsServer.stop(); state.httpsServer = null; }); + +afterEach(() => { + sinon.restore(); +});