build(aio): upgrade lighthouse to v2.1

This commit is contained in:
Georgios Kalpakas 2017-06-13 17:08:31 +03:00 committed by Alex Rickabaugh
parent d378a29565
commit f73a4c229c
3 changed files with 42 additions and 54 deletions

View File

@ -97,7 +97,7 @@
"karma-coverage-istanbul-reporter": "^1.3.0", "karma-coverage-istanbul-reporter": "^1.3.0",
"karma-jasmine": "^1.1.0", "karma-jasmine": "^1.1.0",
"karma-jasmine-html-reporter": "^0.2.2", "karma-jasmine-html-reporter": "^0.2.2",
"lighthouse": "^1.6.3", "lighthouse": "^2.1.0",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"lunr": "^2.1.0", "lunr": "^2.1.0",
"protractor": "~5.1.0", "protractor": "~5.1.0",

View File

@ -12,17 +12,13 @@
// Imports // Imports
const lighthouse = require('lighthouse'); const lighthouse = require('lighthouse');
const ChromeLauncher = require('lighthouse/lighthouse-cli/chrome-launcher').ChromeLauncher; const chromeLauncher = require('lighthouse/chrome-launcher/chrome-launcher');
const Printer = require('lighthouse/lighthouse-cli/printer'); const printer = require('lighthouse/lighthouse-cli/printer');
const config = require('lighthouse/lighthouse-core/config/default.json'); const config = require('lighthouse/lighthouse-core/config/default.js');
// Constants // Constants
const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/'; 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 // Specify the path to Chrome on Travis
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;
@ -39,7 +35,7 @@ function _main(args) {
console.log(`Running PWA audit for '${url}'...`); console.log(`Running PWA audit for '${url}'...`);
if (isOnHttp) { if (isOnHttp) {
ignoreHttpsAudits(config.aggregations); ignoreHttpsAudits(config);
} }
launchChromeAndRunLighthouse(url, {}, config). launchChromeAndRunLighthouse(url, {}, config).
@ -58,31 +54,29 @@ function evaluateScore(expectedScore, actualScore) {
} }
} }
function ignoreHttpsAudits(aggregations) { function ignoreHttpsAudits(config) {
const httpsAudits = [ const httpsAudits = [
'redirects-http' 'redirects-http'
]; ];
console.info(`Ignoring HTTPS-related audits (${httpsAudits.join(', ')})...`); console.info(`Ignoring HTTPS-related audits (${httpsAudits.join(', ')})...`);
aggregations.forEach(aggregation => config.categories.pwa.audits.forEach(audit => {
aggregation.items.forEach(item => if (httpsAudits.indexOf(audit.id) !== -1) {
httpsAudits.map(key => item.audits[key]).forEach(audit => // Ugly hack to ignore HTTPS-related audits.
// Ugly hack to ignore HTTPS-related audits (i.e. simulate them passing). // Only meant for use during development.
// Only meant for use during development. audit.weight = 0;
audit && (audit.expectedValue = !audit.expectedValue)))); }
});
} }
function launchChromeAndRunLighthouse(url, flags, config) { function launchChromeAndRunLighthouse(url, flags, config) {
const launcher = new ChromeLauncher({autoSelectChrome: true}); return chromeLauncher.launch().then(chrome => {
flags.port = chrome.port;
return launcher.run(). return lighthouse(url, flags, config).
then(() => lighthouse(url, flags, config)). then(results => chrome.kill().then(() => results)).
// Avoid race condition by adding a delay before killing Chrome. catch(err => chrome.kill().then(() => { throw err; }, () => { throw err; }));
// (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; }));
} }
function onError(err) { function onError(err) {
@ -105,16 +99,15 @@ function parseInput(args) {
} }
function processResults(results, logFile) { function processResults(results, logFile) {
let promise = Promise.resolve();
if (logFile) { if (logFile) {
console.log(`Saving results in '${logFile}'...`); console.log(`Saving results in '${logFile}'...`);
console.log(`(LightHouse viewer: ${VIEWER_URL})`); console.log(`(LightHouse viewer: ${VIEWER_URL})`);
results.artifacts = undefined; // Avoid circular dependency errors. results.artifacts = undefined; // Too large for the logs.
Printer.write(results, 'json', logFile); promise = printer.write(results, 'json', logFile);
} }
const scoredAggregations = results.aggregations.filter(a => a.scored); return promise.then(() => Math.round(results.score));
const total = scoredAggregations.reduce((sum, a) => sum + a.total, 0);
return Math.round((total / scoredAggregations.length) * 100);
} }

View File

@ -574,9 +574,9 @@ aws4@^1.2.1:
version "1.6.0" version "1.6.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
axe-core@2.1.7: axe-core@2.2.1:
version "2.1.7" version "2.2.1"
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-2.1.7.tgz#4f66f2b3ee3b58ec2d3db4339dd124c5b33b79c3" resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-2.2.1.tgz#d8fe7be13e2d80e407f96d3374ed64d5fb1c3e54"
babar@0.0.3: babar@0.0.3:
version "0.0.3" version "0.0.3"
@ -1784,7 +1784,7 @@ date-now@^0.1.4:
version "0.1.4" version "0.1.4"
resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b" 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" version "2.6.7"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.7.tgz#92bad1f6d05bbb6bba22cca88bcd0ec894c2861e" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.7.tgz#92bad1f6d05bbb6bba22cca88bcd0ec894c2861e"
dependencies: dependencies:
@ -1814,12 +1814,6 @@ debug@2.6.3:
dependencies: dependencies:
ms "0.7.2" 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: decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2:
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" 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" url-join "0.0.1"
valid-url "^1" valid-url "^1"
jpeg-js@^0.1.2: jpeg-js@0.1.2, jpeg-js@^0.1.2:
version "0.1.2" version "0.1.2"
resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.1.2.tgz#135b992c0575c985cfa0f494a3227ed238583ece" 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: dependencies:
object-assign "^4.1.0" object-assign "^4.1.0"
lighthouse@^1.6.3: lighthouse@^2.1.0:
version "1.6.5" version "2.1.0"
resolved "https://registry.yarnpkg.com/lighthouse/-/lighthouse-1.6.5.tgz#7e06a7025c8be298b6f912dbc2f15def1d4b6531" resolved "https://registry.yarnpkg.com/lighthouse/-/lighthouse-2.1.0.tgz#caa6a3993e3b22098f82f2f745e16cda84c71aa3"
dependencies: dependencies:
axe-core "2.1.7" axe-core "2.2.1"
chrome-devtools-frontend "1.0.422034" chrome-devtools-frontend "1.0.422034"
debug "2.2.0" debug "2.2.0"
devtools-timeline-model "1.1.6" devtools-timeline-model "1.1.6"
gl-matrix "2.3.2" gl-matrix "2.3.2"
handlebars "4.0.5" handlebars "4.0.5"
jpeg-js "0.1.2"
json-stringify-safe "5.0.1" json-stringify-safe "5.0.1"
marked "0.3.6" marked "0.3.6"
metaviewport-parser "0.0.1" metaviewport-parser "0.0.1"
@ -4241,7 +4236,7 @@ lighthouse@^1.6.3:
opn "4.0.2" opn "4.0.2"
rimraf "2.2.8" rimraf "2.2.8"
semver "5.3.0" semver "5.3.0"
speedline "1.0.3" speedline "1.2.0"
update-notifier "^2.1.0" update-notifier "^2.1.0"
whatwg-url "4.0.0" whatwg-url "4.0.0"
ws "1.1.1" ws "1.1.1"
@ -4650,14 +4645,14 @@ ms@0.7.2:
version "0.7.2" version "0.7.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765" 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: ms@2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" 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: mute-stream@0.0.5:
version "0.0.5" version "0.0.5"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0" 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" select-hose "^2.0.0"
spdy-transport "^2.0.15" spdy-transport "^2.0.15"
speedline@1.0.3: speedline@1.2.0:
version "1.0.3" version "1.2.0"
resolved "https://registry.yarnpkg.com/speedline/-/speedline-1.0.3.tgz#ee1d98c18d583a2d8488aaded2db9334b943dbbd" resolved "https://registry.yarnpkg.com/speedline/-/speedline-1.2.0.tgz#f5828dcf8e9b96a9f6c1da8ab298538820c6668d"
dependencies: dependencies:
babar "0.0.3" babar "0.0.3"
image-ssim "^0.2.0" image-ssim "^0.2.0"