build: several minor fixes related to using puppeteer (#35381)

This is a follow-up to #35049 with a few minor fixes related to using
the browser provided by `puppeteer` to run tests. Included fixes:

- Make the `webdriver-manager-update.js` really portable. (Previously,
  it needed to be run from the directory that contained the
  `node_modules/` directory. Now, it can be executed from a subdirectory
  and will correctly resolve dependencies.)

- Use the `puppeteer`-based setup in AIO unit and e2e tests to ensure
  that the downloaded ChromeDriver version matches the browser version
  used in tests.

- Use the `puppeteer`-based setup in the `aio_monitoring_stable` CI job
  (as happens with `aio_monitoring_next`).

- Use the [recommended way][1] of getting the browser port when using
  `puppeteer` with `lighthouse` and avoid hard-coding the remote
  debugging port (to be able to handle multiple instances running
  concurrently).

[1]: https://github.com/GoogleChrome/lighthouse/blame/51df179a0/docs/puppeteer.md#L49

PR Close #35381
This commit is contained in:
George Kalpakas
2020-02-13 16:46:38 +02:00
committed by Alex Rickabaugh
parent d7c4f40171
commit ab8199f7c9
7 changed files with 24 additions and 26 deletions

View File

@ -10,17 +10,19 @@
*/
// Use process.cwd() so that this script is portable and can be used in /aio
// where this will require /aio/node_modules/puppeteer
const puppeteerVersion = require(`${process.cwd()}/node_modules/puppeteer/package.json`).version;
const puppeteerPkgPath = require.resolve('puppeteer/package.json', {paths: [process.cwd()]});
const puppeteerVersion = require(puppeteerPkgPath).version;
const chromeVersionMap = require('./puppeteer-chrome-versions');
const spawnSync = require('child_process').spawnSync;
const version = chromeVersionMap[puppeteerVersion];
if (!version) {
console.error(`[webdriver-manager-update.js] Error: Could not Chrome version for Puppeteer version '${puppeteerVersion}' in Chrome/Puppeteer version map. Please update /scripts/puppeteer-chrome-versions.js.`);
console.error(`[webdriver-manager-update.js] Error: Could not find Chrome version for Puppeteer version '${puppeteerVersion}' in Chrome/Puppeteer version map. Please update /scripts/puppeteer-chrome-versions.js.`);
process.exit(1);
}
const args = [
'webdriver-manager',
'update',
'--gecko=false',
'--standalone=false',
@ -30,13 +32,12 @@ const args = [
...process.argv.slice(2),
];
const isWindows = process.platform === 'win32';
const result = spawnSync(`${process.cwd()}/node_modules/.bin/webdriver-manager${isWindows ? '.cmd' : ''}`, args, {stdio: 'inherit'});
const result = spawnSync('yarn', args, {shell: true, stdio: 'inherit'});
if (result.error) {
console.error(`[webdriver-manager-update.js] Call to 'webdriver-manager update ${args.join(' ')}' failed with error code ${result.error.code}`);
console.error(`[webdriver-manager-update.js] Call to 'yarn ${args.join(' ')}' failed with error code ${result.error.code}`);
process.exit(result.status);
}
if (result.status) {
console.error(`[webdriver-manager-update.js] Call to 'webdriver-manager update ${args.join(' ')}' failed with error code ${result.status}`);
console.error(`[webdriver-manager-update.js] Call to 'yarn ${args.join(' ')}' failed with error code ${result.status}`);
process.exit(result.status);
}
}