Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions aio/scripts/test-pwa-score.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -37,19 +37,19 @@ _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}'...`);

// If testing on HTTP, skip HTTPS-specific tests.
// (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 {
Expand Down Expand Up @@ -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});
}