test(docs-infra): improve logging output in test-pwa-score[-localhost]
(#26459)
PR Close #26459
This commit is contained in:
parent
485d67bfed
commit
05f279df49
@ -30,7 +30,7 @@
|
|||||||
"postsetup-local": "yarn postsetup",
|
"postsetup-local": "yarn postsetup",
|
||||||
"set-opensearch-url": "node --eval \"const sh = require('shelljs'); sh.set('-e'); sh.sed('-i', /PLACEHOLDER_URL/g, process.argv[1], 'dist/assets/opensearch.xml');\"",
|
"set-opensearch-url": "node --eval \"const sh = require('shelljs'); sh.set('-e'); sh.sed('-i', /PLACEHOLDER_URL/g, process.argv[1], 'dist/assets/opensearch.xml');\"",
|
||||||
"test-pwa-score": "node scripts/test-pwa-score",
|
"test-pwa-score": "node scripts/test-pwa-score",
|
||||||
"test-pwa-score-localhost": "run-p --race \"~~http-server dist -p 4200 --silent\" \"test-pwa-score http://localhost:4200 {1}\" --",
|
"test-pwa-score-localhost": "run-p --race \"~~http-server dist -p 4200 --silent\" \"test-pwa-score http://localhost:4200 {1} {2}\" --",
|
||||||
"example-e2e": "yarn example-check-local && node ./tools/examples/run-example-e2e",
|
"example-e2e": "yarn example-check-local && node ./tools/examples/run-example-e2e",
|
||||||
"example-lint": "tslint -c \"content/examples/tslint.json\" \"content/examples/**/*.ts\" -e \"content/examples/styleguide/**/*.avoid.ts\"",
|
"example-lint": "tslint -c \"content/examples/tslint.json\" \"content/examples/**/*.ts\" -e \"content/examples/styleguide/**/*.avoid.ts\"",
|
||||||
"example-use-local": "node tools/ng-packages-installer overwrite ./tools/examples/shared --debug",
|
"example-use-local": "node tools/ng-packages-installer overwrite ./tools/examples/shared --debug",
|
||||||
|
@ -15,9 +15,11 @@ const chromeLauncher = require('chrome-launcher');
|
|||||||
const lighthouse = require('lighthouse');
|
const lighthouse = require('lighthouse');
|
||||||
const printer = require('lighthouse/lighthouse-cli/printer');
|
const printer = require('lighthouse/lighthouse-cli/printer');
|
||||||
const config = require('lighthouse/lighthouse-core/config/default-config.js');
|
const config = require('lighthouse/lighthouse-core/config/default-config.js');
|
||||||
|
const logger = require('lighthouse-logger');
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const CHROME_LAUNCH_OPTS = {};
|
const CHROME_LAUNCH_OPTS = {};
|
||||||
|
const LIGHTHOUSE_FLAGS = {logLevel: 'info'};
|
||||||
const SKIPPED_HTTPS_AUDITS = ['redirects-http'];
|
const SKIPPED_HTTPS_AUDITS = ['redirects-http'];
|
||||||
const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/';
|
const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/';
|
||||||
|
|
||||||
@ -26,6 +28,7 @@ const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/';
|
|||||||
if (process.env.TRAVIS) {
|
if (process.env.TRAVIS) {
|
||||||
process.env.LIGHTHOUSE_CHROMIUM_PATH = process.env.CHROME_BIN;
|
process.env.LIGHTHOUSE_CHROMIUM_PATH = process.env.CHROME_BIN;
|
||||||
CHROME_LAUNCH_OPTS.chromeFlags = ['--no-sandbox'];
|
CHROME_LAUNCH_OPTS.chromeFlags = ['--no-sandbox'];
|
||||||
|
LIGHTHOUSE_FLAGS.logLevel = 'error';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run
|
// Run
|
||||||
@ -42,18 +45,20 @@ function _main(args) {
|
|||||||
skipHttpsAudits(config);
|
skipHttpsAudits(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
launchChromeAndRunLighthouse(url, {}, config).
|
logger.setLevel(LIGHTHOUSE_FLAGS.logLevel);
|
||||||
|
|
||||||
|
launchChromeAndRunLighthouse(url, LIGHTHOUSE_FLAGS, config).
|
||||||
then(results => processResults(results, logFile)).
|
then(results => processResults(results, logFile)).
|
||||||
then(score => evaluateScore(minScore, score)).
|
then(score => evaluateScore(minScore, score)).
|
||||||
catch(onError);
|
catch(onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
function evaluateScore(expectedScore, actualScore) {
|
function evaluateScore(expectedScore, actualScore) {
|
||||||
console.log('Lighthouse PWA score:');
|
console.log('\nLighthouse PWA score:');
|
||||||
console.log(` - Expected: ${expectedScore} / 100 (or higher)`);
|
console.log(` - Expected: ${expectedScore.toFixed(0).padStart(3)} / 100 (or higher)`);
|
||||||
console.log(` - Actual: ${actualScore} / 100`);
|
console.log(` - Actual: ${actualScore.toFixed(0).padStart(3)} / 100\n`);
|
||||||
|
|
||||||
if (actualScore < expectedScore) {
|
if (isNaN(actualScore) || (actualScore < expectedScore)) {
|
||||||
throw new Error(`PWA score is too low. (${actualScore} < ${expectedScore})`);
|
throw new Error(`PWA score is too low. (${actualScore} < ${expectedScore})`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,7 +104,18 @@ function processResults(results, logFile) {
|
|||||||
return printer.write(report, printer.OutputMode.json, logFile);
|
return printer.write(report, printer.OutputMode.json, logFile);
|
||||||
}
|
}
|
||||||
}).
|
}).
|
||||||
then(() => Math.round(categories.pwa.score * 100));
|
then(() => {
|
||||||
|
const categoryData = Object.keys(categories).map(name => categories[name]);
|
||||||
|
const maxTitleLen = Math.max(...categoryData.map(({title}) => title.length));
|
||||||
|
|
||||||
|
console.log('\nAudit scores:');
|
||||||
|
categoryData.forEach(({title, score}) => {
|
||||||
|
const paddedTitle = `${title}:`.padEnd(maxTitleLen + 1);
|
||||||
|
const paddedScore = (score * 100).toFixed(0).padStart(3);
|
||||||
|
console.log(` - ${paddedTitle} ${paddedScore} / 100`);
|
||||||
|
});
|
||||||
|
}).
|
||||||
|
then(() => categories.pwa.score * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
function skipHttpsAudits(config) {
|
function skipHttpsAudits(config) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user