test(docs-infra): print the browser version in `audit-web-app.js` to help debugging (#41103)

This commit updates the `audit-web-app.js` script (used to run PWA and
a11y tests on angular.io) to also print the version of the browser used
to run the tests. This can help when debugging a CI failure.

PR Close #41103
This commit is contained in:
George Kalpakas 2021-03-06 12:42:55 +02:00 committed by Andrew Kushnir
parent 44bb78dbbd
commit e59246cf5c
1 changed files with 22 additions and 19 deletions

View File

@ -60,9 +60,16 @@ async function _main(args) {
try {
console.log('');
const startTime = Date.now();
const results = await launchChromeAndRunLighthouse(url, lhFlags, lhConfig);
const browser = await puppeteer.launch();
const browserVersion = await browser.version();
const results = await runLighthouse(browser, url, lhFlags, lhConfig);
console.log(
`\n Browser version: ${browserVersion}` +
`\n Lighthouse version: ${results.lhr.lighthouseVersion}`);
const success = await processResults(results, minScores, logFile);
console.log(`\n(Completed in ${((Date.now() - startTime) / 1000).toFixed(1)}s.)\n`);
console.log(`\n (Completed in ${((Date.now() - startTime) / 1000).toFixed(1)}s.)\n`);
if (!success) {
throw new Error('One or more scores are too low.');
@ -76,17 +83,6 @@ function formatScore(score) {
return `${(score * 100).toFixed(0).padStart(3)}`;
}
async function launchChromeAndRunLighthouse(url, flags, config) {
const browser = await puppeteer.launch();
flags.port = (new URL(browser.wsEndpoint())).port;
try {
return await lighthouse(url, flags, config);
} finally {
await browser.close();
}
}
function onError(err) {
console.error(err);
console.error('');
@ -136,19 +132,17 @@ function parseMinScores(raw) {
}
async function processResults(results, minScores, logFile) {
const lhVersion = results.lhr.lighthouseVersion;
const categories = results.lhr.categories;
const report = results.report;
if (logFile) {
console.log(`\nSaving results in '${logFile}'...`);
console.log(` LightHouse viewer: ${VIEWER_URL}`);
console.log(`\n Saving results in '${logFile}'...`);
console.log(` LightHouse viewer: ${VIEWER_URL}`);
await printer.write(report, printer.OutputMode.json, logFile);
}
console.log(`\nLighthouse version: ${lhVersion}`);
console.log('\nAudit results:');
console.log('\n Audit results:');
const maxTitleLen = Math.max(...Object.values(categories).map(({title}) => title.length));
const success = Object.keys(categories).sort().reduce((aggr, cat) => {
@ -158,10 +152,19 @@ async function processResults(results, minScores, logFile) {
const passed = !isNaN(score) && (score >= minScore);
console.log(
` - ${paddedTitle} ${formatScore(score)} (Required: ${formatScore(minScore)}) ${passed ? 'OK' : 'FAILED'}`);
` - ${paddedTitle} ${formatScore(score)} (Required: ${formatScore(minScore)}) ${passed ? 'OK' : 'FAILED'}`);
return aggr && passed;
}, true);
return success;
}
async function runLighthouse(browser, url, flags, config) {
try {
flags.port = (new URL(browser.wsEndpoint())).port;
return await lighthouse(url, flags, config);
} finally {
await browser.close();
}
}