fix: set revision based on PUPPETEER_PRODUCT (#5643)
This commit is contained in:
parent
d817ae5a4b
commit
35989a78ba
10
.travis.yml
10
.travis.yml
@ -20,17 +20,17 @@ jobs:
|
|||||||
before_install:
|
before_install:
|
||||||
- "export DISPLAY=:99.0"
|
- "export DISPLAY=:99.0"
|
||||||
- "sh -e /etc/init.d/xvfb start"
|
- "sh -e /etc/init.d/xvfb start"
|
||||||
|
# populate .local-firefox for launcher tests
|
||||||
|
- PUPPETEER_PRODUCT=firefox npm install
|
||||||
script: ./travis/chromium.sh
|
script: ./travis/chromium.sh
|
||||||
- node_js: "10.19.0"
|
- node_js: "10.19.0"
|
||||||
dist: trusty
|
dist: trusty
|
||||||
env:
|
env:
|
||||||
- FIREFOX=true
|
- FIREFOX=true
|
||||||
- FIREFOX_HOME=$TRAVIS_HOME/firefox-latest
|
|
||||||
before_install:
|
before_install:
|
||||||
- "export DISPLAY=:99.0"
|
- "export DISPLAY=:99.0"
|
||||||
- "sh -e /etc/init.d/xvfb start"
|
- "sh -e /etc/init.d/xvfb start"
|
||||||
- "pyenv shell 3.6 && pip3 install --user mozdownload"
|
# install step will add .local-chromium for launcher tests
|
||||||
- "rm -rf $FIREFOX_HOME && mozdownload -t daily -d $FIREFOX_HOME/latest.tar.bz --log-level DEBUG"
|
- PUPPETEER_PRODUCT=firefox npm install
|
||||||
- "cd $FIREFOX_HOME; tar -xvf latest.tar.bz; cd -; ls $FIREFOX_HOME/firefox/firefox"
|
|
||||||
script:
|
script:
|
||||||
- "BINARY=$FIREFOX_HOME/firefox/firefox npm run funit"
|
- "npm run funit"
|
||||||
|
8
index.js
8
index.js
@ -29,10 +29,14 @@ Page.prototype.emulateMedia = Page.prototype.emulateMediaType;
|
|||||||
// If node does not support async await, use the compiled version.
|
// If node does not support async await, use the compiled version.
|
||||||
const Puppeteer = require('./lib/Puppeteer');
|
const Puppeteer = require('./lib/Puppeteer');
|
||||||
const packageJson = require('./package.json');
|
const packageJson = require('./package.json');
|
||||||
const preferredRevision = packageJson.puppeteer.chromium_revision;
|
let preferredRevision = packageJson.puppeteer.chromium_revision;
|
||||||
const isPuppeteerCore = packageJson.name === 'puppeteer-core';
|
const isPuppeteerCore = packageJson.name === 'puppeteer-core';
|
||||||
|
// puppeteer-core ignores environment variables
|
||||||
|
const product = isPuppeteerCore ? undefined : process.env.PUPPETEER_PRODUCT || process.env.npm_config_puppeteer_product || process.env.npm_package_config_puppeteer_product;
|
||||||
|
if (!isPuppeteerCore && product === 'firefox')
|
||||||
|
preferredRevision = packageJson.puppeteer.firefox_revision;
|
||||||
|
|
||||||
const puppeteer = new Puppeteer(__dirname, preferredRevision, isPuppeteerCore);
|
const puppeteer = new Puppeteer(__dirname, preferredRevision, isPuppeteerCore, product);
|
||||||
|
|
||||||
// The introspection in `Helper.installAsyncStackHooks` references `Puppeteer._launcher`
|
// The introspection in `Helper.installAsyncStackHooks` references `Puppeteer._launcher`
|
||||||
// before the Puppeteer ctor is called, such that an invalid Launcher is selected at import,
|
// before the Puppeteer ctor is called, such that an invalid Launcher is selected at import,
|
||||||
|
@ -411,14 +411,7 @@ class FirefoxLauncher {
|
|||||||
firefoxArguments.push(temporaryUserDataDir);
|
firefoxArguments.push(temporaryUserDataDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace 'latest' placeholder with actual downloaded revision
|
await this._updateRevision();
|
||||||
if (this._preferredRevision === 'latest') {
|
|
||||||
const browserFetcher = new BrowserFetcher(this._projectRoot, {product: this.product});
|
|
||||||
const localRevisions = await browserFetcher.localRevisions();
|
|
||||||
if (localRevisions[0])
|
|
||||||
this._preferredRevision = localRevisions[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
let firefoxExecutable = executablePath;
|
let firefoxExecutable = executablePath;
|
||||||
if (!executablePath) {
|
if (!executablePath) {
|
||||||
const {missingText, executablePath} = resolveExecutablePath(this);
|
const {missingText, executablePath} = resolveExecutablePath(this);
|
||||||
@ -480,6 +473,16 @@ class FirefoxLauncher {
|
|||||||
return resolveExecutablePath(this).executablePath;
|
return resolveExecutablePath(this).executablePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _updateRevision() {
|
||||||
|
// replace 'latest' placeholder with actual downloaded revision
|
||||||
|
if (this._preferredRevision === 'latest') {
|
||||||
|
const browserFetcher = new BrowserFetcher(this._projectRoot, { product: this.product });
|
||||||
|
const localRevisions = await browserFetcher.localRevisions();
|
||||||
|
if (localRevisions[0])
|
||||||
|
this._preferredRevision = localRevisions[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
|
@ -23,11 +23,14 @@ module.exports = class {
|
|||||||
* @param {string} projectRoot
|
* @param {string} projectRoot
|
||||||
* @param {string} preferredRevision
|
* @param {string} preferredRevision
|
||||||
* @param {boolean} isPuppeteerCore
|
* @param {boolean} isPuppeteerCore
|
||||||
|
* @param {string} productName
|
||||||
*/
|
*/
|
||||||
constructor(projectRoot, preferredRevision, isPuppeteerCore) {
|
constructor(projectRoot, preferredRevision, isPuppeteerCore, productName) {
|
||||||
this._projectRoot = projectRoot;
|
this._projectRoot = projectRoot;
|
||||||
this._preferredRevision = preferredRevision;
|
this._preferredRevision = preferredRevision;
|
||||||
this._isPuppeteerCore = isPuppeteerCore;
|
this._isPuppeteerCore = isPuppeteerCore;
|
||||||
|
// track changes to Launcher configuration via options or environment variables
|
||||||
|
this.__productName = productName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +38,8 @@ module.exports = class {
|
|||||||
* @return {!Promise<!Puppeteer.Browser>}
|
* @return {!Promise<!Puppeteer.Browser>}
|
||||||
*/
|
*/
|
||||||
launch(options = {}) {
|
launch(options = {}) {
|
||||||
this._productName = options.product;
|
if (options.product)
|
||||||
|
this._productName = options.product;
|
||||||
return this._launcher.launch(options);
|
return this._launcher.launch(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +48,8 @@ module.exports = class {
|
|||||||
* @return {!Promise<!Puppeteer.Browser>}
|
* @return {!Promise<!Puppeteer.Browser>}
|
||||||
*/
|
*/
|
||||||
connect(options) {
|
connect(options) {
|
||||||
this._productName = options.product;
|
if (options.product)
|
||||||
|
this._productName = options.product;
|
||||||
return this._launcher.connect(options);
|
return this._launcher.connect(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +57,8 @@ module.exports = class {
|
|||||||
* @param {string} name
|
* @param {string} name
|
||||||
*/
|
*/
|
||||||
set _productName(name) {
|
set _productName(name) {
|
||||||
this._changedProduct = this.__productName !== name;
|
if (this.__productName !== name)
|
||||||
|
this._changedProduct = true;
|
||||||
this.__productName = name;
|
this.__productName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,6 +353,35 @@ describe('Launcher specs', function() {
|
|||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('Puppeteer.launch', function() {
|
||||||
|
let productName;
|
||||||
|
|
||||||
|
before(async() => {
|
||||||
|
const {puppeteer} = getTestState();
|
||||||
|
productName = puppeteer._productName;
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async() => {
|
||||||
|
const {puppeteer} = getTestState();
|
||||||
|
puppeteer._lazyLauncher = undefined;
|
||||||
|
puppeteer._productName = productName;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be able to launch different products', async() => {
|
||||||
|
const {puppeteer} = getTestState();
|
||||||
|
|
||||||
|
const products = ['firefox', 'chrome'];
|
||||||
|
for (const product of products) {
|
||||||
|
const browser = await puppeteer.launch({product});
|
||||||
|
const userAgent = await browser.userAgent();
|
||||||
|
await browser.close();
|
||||||
|
if (product === 'chrome')
|
||||||
|
expect(userAgent).toContain('Chrome');
|
||||||
|
else
|
||||||
|
expect(userAgent).toContain('Firefox');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('Puppeteer.connect', function() {
|
describe('Puppeteer.connect', function() {
|
||||||
it('should be able to connect multiple times to the same browser', async() => {
|
it('should be able to connect multiple times to the same browser', async() => {
|
||||||
const { puppeteer, defaultBrowserOptions} = getTestState();
|
const { puppeteer, defaultBrowserOptions} = getTestState();
|
||||||
|
@ -59,14 +59,18 @@ const defaultBrowserOptions = {
|
|||||||
dumpio: !!process.env.DUMPIO,
|
dumpio: !!process.env.DUMPIO,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
(async() => {
|
||||||
|
if (defaultBrowserOptions.executablePath) {
|
||||||
|
console.warn(`WARN: running ${product} tests with ${defaultBrowserOptions.executablePath}`);
|
||||||
|
} else {
|
||||||
|
if (product === 'firefox')
|
||||||
|
await puppeteer._launcher._updateRevision();
|
||||||
|
const executablePath = puppeteer.executablePath();
|
||||||
|
if (!fs.existsSync(executablePath))
|
||||||
|
throw new Error(`Browser is not downloaded at ${executablePath}. Run 'npm install' and try to re-run tests`);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
if (defaultBrowserOptions.executablePath) {
|
|
||||||
console.warn(`WARN: running ${product} tests with ${defaultBrowserOptions.executablePath}`);
|
|
||||||
} else {
|
|
||||||
const executablePath = puppeteer.executablePath();
|
|
||||||
if (!fs.existsSync(executablePath))
|
|
||||||
throw new Error(`Browser is not downloaded at ${executablePath}. Run 'npm install' and try to re-run tests`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const setupGoldenAssertions = () => {
|
const setupGoldenAssertions = () => {
|
||||||
const suffix = product.toLowerCase();
|
const suffix = product.toLowerCase();
|
||||||
|
Loading…
Reference in New Issue
Block a user