ci(aio): log the full PWA testing results

This will help diagnose errors or regressions in PWA scores.
This commit is contained in:
Georgios Kalpakas 2017-05-15 15:43:08 +03:00 committed by Pete Bacon Darwin
parent b40aae54b7
commit 35d1922006
4 changed files with 29 additions and 18 deletions

View File

@ -69,5 +69,5 @@ readonly relevantChangedFilesCount=$(git diff --name-only $TRAVIS_COMMIT_RANGE |
fi fi
# Run PWA-score tests # Run PWA-score tests
yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE" yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE" "$PWA_RESULTS_LOG"
) )

View File

@ -20,5 +20,5 @@ DEPLOYED_URL=https://$FIREBASE_PROJECT_ID.firebaseapp.com
# Run PWA-score tests # Run PWA-score tests
# TODO(gkalpak): Figure out why this fails and re-enable. # TODO(gkalpak): Figure out why this fails and re-enable.
sleep 10 sleep 10
yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE" || true yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE" "$PWA_RESULTS_LOG" || true
) )

View File

@ -2,11 +2,10 @@
/** /**
* Usage: * Usage:
* node scripts/test-pwa-score [<url> [<min-score>]] * node scripts/test-pwa-score <url> <min-score> [<log-file>]
* *
* Defaults: * Fails if the score is below `<min-score>`.
* url: http://localhost:4200 * If `<log-file>` is defined, the full results will be logged there.
* minScore: 90
* *
* (Ignores HTTPS-related audits, when run for HTTP URL.) * (Ignores HTTPS-related audits, when run for HTTP URL.)
*/ */
@ -18,7 +17,7 @@ const Printer = require('lighthouse/lighthouse-cli/printer');
const config = require('lighthouse/lighthouse-core/config/default.json'); const config = require('lighthouse/lighthouse-core/config/default.json');
// Constants // Constants
const FLAGS = {output: 'json'}; const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/';
// Work-around traceviewer-js bug. // Work-around traceviewer-js bug.
global.atob = str => new Buffer(str, 'base64').toString('binary'); global.atob = str => new Buffer(str, 'base64').toString('binary');
@ -34,7 +33,7 @@ _main(process.argv.slice(2));
// Functions - Definitions // Functions - Definitions
function _main(args) { function _main(args) {
const {url, minScore} = parseInput(args); const {url, minScore, logFile} = parseInput(args);
const isOnHttp = /^http:/.test(url); const isOnHttp = /^http:/.test(url);
console.log(`Running PWA audit for '${url}'...`); console.log(`Running PWA audit for '${url}'...`);
@ -43,8 +42,8 @@ function _main(args) {
ignoreHttpsAudits(config.aggregations); ignoreHttpsAudits(config.aggregations);
} }
launchChromeAndRunLighthouse(url, FLAGS, config). launchChromeAndRunLighthouse(url, {}, config).
then(getScore). then(results => processResults(results, logFile)).
then(score => evaluateScore(minScore, score)). then(score => evaluateScore(minScore, score)).
catch(onError); catch(onError);
} }
@ -59,13 +58,6 @@ function evaluateScore(expectedScore, actualScore) {
} }
} }
function getScore(results) {
const scoredAggregations = results.aggregations.filter(a => a.scored);
const total = scoredAggregations.reduce((sum, a) => sum + a.total, 0);
return Math.round((total / scoredAggregations.length) * 100);
}
function ignoreHttpsAudits(aggregations) { function ignoreHttpsAudits(aggregations) {
const httpsAudits = [ const httpsAudits = [
'is-on-https', 'is-on-https',
@ -99,6 +91,7 @@ function onError(err) {
function parseInput(args) { function parseInput(args) {
const url = args[0]; const url = args[0];
const minScore = Number(args[1]); const minScore = Number(args[1]);
const logFile = args[2];
if (!url) { if (!url) {
onError('Invalid arguments: <URL> not specified.'); onError('Invalid arguments: <URL> not specified.');
@ -106,5 +99,20 @@ function parseInput(args) {
onError('Invalid arguments: <MIN_SCORE> not specified or not a number.'); onError('Invalid arguments: <MIN_SCORE> not specified or not a number.');
} }
return {url, minScore}; return {url, minScore, logFile};
}
function processResults(results, logFile) {
if (logFile) {
console.log(`Saving results in '${logFile}'...`);
console.log(`(LightHouse viewer: ${VIEWER_URL})`);
results.artifacts = undefined; // Avoid circular dependency errors.
Printer.write(results, 'json', logFile);
}
const scoredAggregations = results.aggregations.filter(a => a.scored);
const total = scoredAggregations.reduce((sum, a) => sum + a.total, 0);
return Math.round((total / scoredAggregations.length) * 100);
} }

View File

@ -120,6 +120,9 @@ setEnvVar PATH $HOME/.yarn/bin:$PATH
setEnvVar NODE_PATH ${NODE_PATH:-}:${PROJECT_ROOT}/dist/all:${PROJECT_ROOT}/dist/tools setEnvVar NODE_PATH ${NODE_PATH:-}:${PROJECT_ROOT}/dist/all:${PROJECT_ROOT}/dist/tools
setEnvVar LOGS_DIR /tmp/angular-build/logs setEnvVar LOGS_DIR /tmp/angular-build/logs
# Log file for full PWA testing results
setEnvVar PWA_RESULTS_LOG $LOGS_DIR/pwa-results.json
# strip leading "/home/travis/build/angular/angular/" or "./" path. Could this be done in one shot? # strip leading "/home/travis/build/angular/angular/" or "./" path. Could this be done in one shot?
CURRENT_SHELL_SOURCE_FILE=${BASH_SOURCE#${PROJECT_ROOT}/} CURRENT_SHELL_SOURCE_FILE=${BASH_SOURCE#${PROJECT_ROOT}/}
export CURRENT_SHELL_SOURCE_FILE=${CURRENT_SHELL_SOURCE_FILE#./} export CURRENT_SHELL_SOURCE_FILE=${CURRENT_SHELL_SOURCE_FILE#./}