diff --git a/aio/scripts/test-pwa-score.js b/aio/scripts/test-pwa-score.js index 2b1bff2bfd..30e642df4c 100644 --- a/aio/scripts/test-pwa-score.js +++ b/aio/scripts/test-pwa-score.js @@ -21,9 +21,9 @@ const logger = require('lighthouse-logger'); // Constants const CHROME_LAUNCH_OPTS = {}; const LIGHTHOUSE_FLAGS = {logLevel: 'info'}; -const LONG_WAIT_FOR_SW_DELAY = 5000; const SKIPPED_HTTPS_AUDITS = ['redirects-http']; const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/'; +const WAIT_FOR_SW_DELAY = 5000; // Be less verbose on CI. if (process.env.CI) { @@ -37,8 +37,12 @@ _main(process.argv.slice(2)); async function _main(args) { const {url, minScore, logFile} = parseInput(args); const isOnHttp = /^http:/.test(url); - const isOnLocalhost = /\/\/localhost\b/.test(url); - const config = {extends: 'lighthouse:default'}; + const config = { + extends: 'lighthouse:default', + // Since the Angular ServiceWorker waits for the app to stabilize before registering, + // wait a few seconds after load to allow Lighthouse to reliably detect it. + passes: [{passName: 'defaultPass', pauseAfterLoadMs: WAIT_FOR_SW_DELAY}], + } console.log(`Running PWA audit for '${url}'...`); @@ -46,10 +50,6 @@ async function _main(args) { // (Note: Browsers special-case localhost and run ServiceWorker even on HTTP.) if (isOnHttp) skipHttpsAudits(config); - // If testing on localhost, where the server has less optimizations (e.g. no file compression), - // wait longer for the ServiceWorker to be registered, so Lighthouse can reliably detect it. - if (isOnLocalhost) waitLongerForSw(config); - logger.setLevel(LIGHTHOUSE_FLAGS.logLevel); try { @@ -133,9 +133,3 @@ function skipHttpsAudits(config) { const settings = config.settings || (config.settings = {}); settings.skipAudits = SKIPPED_HTTPS_AUDITS; } - -function waitLongerForSw(config) { - console.info(`Will wait longer for ServiceWorker (${LONG_WAIT_FOR_SW_DELAY}ms)...`); - const passes = config.passes || (config.passes = []); - passes.push({passName: 'defaultPass', pauseAfterLoadMs: LONG_WAIT_FOR_SW_DELAY}); -}