Warn when given unsupported product name. (#5845)

* Warn when given unsupported product name.

Fixes #5844.

This change means when a user launches Puppeteer with a product name
that is not supported (which at the time of this commit means it's not
`firefox` or `chrome) we will warn them about it.

Decided on just a warning vs an error because the current behaviour is
that we fallback to launching Chrome and I don't think this warrants a
breaking change.
This commit is contained in:
Jack Franklin
2020-05-12 10:30:24 +01:00
committed by GitHub
parent 6099272612
commit b38bb4334f
4 changed files with 29 additions and 0 deletions

View File

@@ -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