From f73a4c229c7f748200f3db6559b91e1c5b85e8c9 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Tue, 13 Jun 2017 17:08:31 +0300 Subject: [PATCH] build(aio): upgrade lighthouse to v2.1 --- aio/package.json | 2 +- aio/scripts/test-pwa-score.js | 53 +++++++++++++++-------------------- aio/yarn.lock | 41 ++++++++++++--------------- 3 files changed, 42 insertions(+), 54 deletions(-) diff --git a/aio/package.json b/aio/package.json index ec01c06780..d24f560bf5 100644 --- a/aio/package.json +++ b/aio/package.json @@ -97,7 +97,7 @@ "karma-coverage-istanbul-reporter": "^1.3.0", "karma-jasmine": "^1.1.0", "karma-jasmine-html-reporter": "^0.2.2", - "lighthouse": "^1.6.3", + "lighthouse": "^2.1.0", "lodash": "^4.17.4", "lunr": "^2.1.0", "protractor": "~5.1.0", diff --git a/aio/scripts/test-pwa-score.js b/aio/scripts/test-pwa-score.js index f87ef3a9e2..388d76651d 100644 --- a/aio/scripts/test-pwa-score.js +++ b/aio/scripts/test-pwa-score.js @@ -12,17 +12,13 @@ // Imports const lighthouse = require('lighthouse'); -const ChromeLauncher = require('lighthouse/lighthouse-cli/chrome-launcher').ChromeLauncher; -const Printer = require('lighthouse/lighthouse-cli/printer'); -const config = require('lighthouse/lighthouse-core/config/default.json'); +const chromeLauncher = require('lighthouse/chrome-launcher/chrome-launcher'); +const printer = require('lighthouse/lighthouse-cli/printer'); +const config = require('lighthouse/lighthouse-core/config/default.js'); // Constants const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/'; -// Work-around traceviewer-js bug. -global.atob = str => new Buffer(str, 'base64').toString('binary'); -global.btoa = str => new Buffer(str, 'binary').toString('base64'); - // Specify the path to Chrome on Travis if (process.env.TRAVIS) { process.env.LIGHTHOUSE_CHROMIUM_PATH = process.env.CHROME_BIN; @@ -39,7 +35,7 @@ function _main(args) { console.log(`Running PWA audit for '${url}'...`); if (isOnHttp) { - ignoreHttpsAudits(config.aggregations); + ignoreHttpsAudits(config); } launchChromeAndRunLighthouse(url, {}, config). @@ -58,31 +54,29 @@ function evaluateScore(expectedScore, actualScore) { } } -function ignoreHttpsAudits(aggregations) { +function ignoreHttpsAudits(config) { const httpsAudits = [ 'redirects-http' ]; console.info(`Ignoring HTTPS-related audits (${httpsAudits.join(', ')})...`); - aggregations.forEach(aggregation => - aggregation.items.forEach(item => - httpsAudits.map(key => item.audits[key]).forEach(audit => - // Ugly hack to ignore HTTPS-related audits (i.e. simulate them passing). - // Only meant for use during development. - audit && (audit.expectedValue = !audit.expectedValue)))); + config.categories.pwa.audits.forEach(audit => { + if (httpsAudits.indexOf(audit.id) !== -1) { + // Ugly hack to ignore HTTPS-related audits. + // Only meant for use during development. + audit.weight = 0; + } + }); } function launchChromeAndRunLighthouse(url, flags, config) { - const launcher = new ChromeLauncher({autoSelectChrome: true}); - - return launcher.run(). - then(() => lighthouse(url, flags, config)). - // Avoid race condition by adding a delay before killing Chrome. - // (See also https://github.com/paulirish/pwmetrics/issues/63#issuecomment-282721068.) - then(results => new Promise(resolve => setTimeout(() => resolve(results), 1000))). - then(results => launcher.kill().then(() => results)). - catch(err => launcher.kill().then(() => { throw err; }, () => { throw err; })); + return chromeLauncher.launch().then(chrome => { + flags.port = chrome.port; + return lighthouse(url, flags, config). + then(results => chrome.kill().then(() => results)). + catch(err => chrome.kill().then(() => { throw err; }, () => { throw err; })); + }); } function onError(err) { @@ -105,16 +99,15 @@ function parseInput(args) { } function processResults(results, logFile) { + let promise = Promise.resolve(); + 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); + results.artifacts = undefined; // Too large for the logs. + promise = 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); + return promise.then(() => Math.round(results.score)); } diff --git a/aio/yarn.lock b/aio/yarn.lock index af00dd1d5c..225abf58a6 100644 --- a/aio/yarn.lock +++ b/aio/yarn.lock @@ -574,9 +574,9 @@ aws4@^1.2.1: version "1.6.0" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" -axe-core@2.1.7: - version "2.1.7" - resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-2.1.7.tgz#4f66f2b3ee3b58ec2d3db4339dd124c5b33b79c3" +axe-core@2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-2.2.1.tgz#d8fe7be13e2d80e407f96d3374ed64d5fb1c3e54" babar@0.0.3: version "0.0.3" @@ -1784,7 +1784,7 @@ date-now@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b" -debug@*, debug@2, debug@2.6.7, debug@^2.1.3, debug@^2.2.0, debug@^2.6.3: +debug@*, debug@2, debug@2.6.7, debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.6.3: version "2.6.7" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.7.tgz#92bad1f6d05bbb6bba22cca88bcd0ec894c2861e" dependencies: @@ -1814,12 +1814,6 @@ debug@2.6.3: dependencies: ms "0.7.2" -debug@^2.1.1: - version "2.6.6" - resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.6.tgz#a9fa6fbe9ca43cf1e79f73b75c0189cbb7d6db5a" - dependencies: - ms "0.7.3" - decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" @@ -3900,7 +3894,7 @@ join-path@^1.0.0: url-join "0.0.1" valid-url "^1" -jpeg-js@^0.1.2: +jpeg-js@0.1.2, jpeg-js@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.1.2.tgz#135b992c0575c985cfa0f494a3227ed238583ece" @@ -4224,16 +4218,17 @@ license-webpack-plugin@^0.4.2: dependencies: object-assign "^4.1.0" -lighthouse@^1.6.3: - version "1.6.5" - resolved "https://registry.yarnpkg.com/lighthouse/-/lighthouse-1.6.5.tgz#7e06a7025c8be298b6f912dbc2f15def1d4b6531" +lighthouse@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/lighthouse/-/lighthouse-2.1.0.tgz#caa6a3993e3b22098f82f2f745e16cda84c71aa3" dependencies: - axe-core "2.1.7" + axe-core "2.2.1" chrome-devtools-frontend "1.0.422034" debug "2.2.0" devtools-timeline-model "1.1.6" gl-matrix "2.3.2" handlebars "4.0.5" + jpeg-js "0.1.2" json-stringify-safe "5.0.1" marked "0.3.6" metaviewport-parser "0.0.1" @@ -4241,7 +4236,7 @@ lighthouse@^1.6.3: opn "4.0.2" rimraf "2.2.8" semver "5.3.0" - speedline "1.0.3" + speedline "1.2.0" update-notifier "^2.1.0" whatwg-url "4.0.0" ws "1.1.1" @@ -4650,14 +4645,14 @@ ms@0.7.2: version "0.7.2" resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765" -ms@0.7.3, ms@^0.7.1: - version "0.7.3" - resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.3.tgz#708155a5e44e33f5fd0fc53e81d0d40a91be1fff" - ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" +ms@^0.7.1: + version "0.7.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.3.tgz#708155a5e44e33f5fd0fc53e81d0d40a91be1fff" + mute-stream@0.0.5: version "0.0.5" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0" @@ -6598,9 +6593,9 @@ spdy@^3.4.1: select-hose "^2.0.0" spdy-transport "^2.0.15" -speedline@1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/speedline/-/speedline-1.0.3.tgz#ee1d98c18d583a2d8488aaded2db9334b943dbbd" +speedline@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/speedline/-/speedline-1.2.0.tgz#f5828dcf8e9b96a9f6c1da8ab298538820c6668d" dependencies: babar "0.0.3" image-ssim "^0.2.0"