From 60e9d2da4f3a204161897d04d5363deb81f20f11 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 17 Apr 2019 09:36:50 +0300 Subject: [PATCH] ci(docs-infra): increase wait for SW on localhost to avoid CI flakes (#29953) The server used for testing on localhost has less optimizations (e.g. serves uncompressed files), so we need to wait longer the ServiceWorker to be loaded and registered to allow Lighthouse to reliably detect it, especially on slower environments (e.g. CI). Related: https://github.com/GoogleChrome/lighthouse/issues/5527#issuecomment-483710849 Fixes #29910 PR Close #29953 --- .circleci/config.yml | 10 ++-------- aio/scripts/test-pwa-score.js | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 68d7ca043c..dc1097322c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -249,10 +249,7 @@ jobs: - run: yarn --cwd aio lint # Run PWA-score tests # (Run before unit and e2e tests, which destroy the `dist/` directory.) - # Temporarily lowering the min required PWA score to avoid flakes on CI. - # TODO(gkalpak): Re-enable once https://github.com/angular/angular/issues/29910 is resolved. - # - run: yarn --cwd aio test-pwa-score-localhost $CI_AIO_MIN_PWA_SCORE - - run: yarn --cwd aio test-pwa-score-localhost 70 + - run: yarn --cwd aio test-pwa-score-localhost $CI_AIO_MIN_PWA_SCORE # Check the bundle sizes. # (Run before unit and e2e tests, which destroy the `dist/` directory.) - run: yarn --cwd aio payload-size @@ -287,10 +284,7 @@ jobs: - run: yarn --cwd aio build-local --progress=false # Run PWA-score tests # (Run before unit and e2e tests, which destroy the `dist/` directory.) - # Temporarily lowering the min required PWA score to avoid flakes on CI. - # TODO(gkalpak): Re-enable once https://github.com/angular/angular/issues/29910 is resolved. - # - run: yarn --cwd aio test-pwa-score-localhost $CI_AIO_MIN_PWA_SCORE - - run: yarn --cwd aio test-pwa-score-localhost 70 + - run: yarn --cwd aio test-pwa-score-localhost $CI_AIO_MIN_PWA_SCORE # Run unit tests - run: yarn --cwd aio test --progress=false --watch=false # Run e2e tests diff --git a/aio/scripts/test-pwa-score.js b/aio/scripts/test-pwa-score.js index b95d4eba6a..2b1bff2bfd 100644 --- a/aio/scripts/test-pwa-score.js +++ b/aio/scripts/test-pwa-score.js @@ -16,12 +16,12 @@ const chromeLauncher = require('chrome-launcher'); const lighthouse = require('lighthouse'); const printer = require('lighthouse/lighthouse-cli/printer'); -const config = require('lighthouse/lighthouse-core/config/default-config.js'); 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/'; @@ -37,12 +37,18 @@ _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'}; console.log(`Running PWA audit for '${url}'...`); - if (isOnHttp) { - skipHttpsAudits(config); - } + // 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); @@ -124,5 +130,12 @@ async function processResults(results, logFile) { function skipHttpsAudits(config) { console.info(`Skipping HTTPS-related audits (${SKIPPED_HTTPS_AUDITS.join(', ')})...`); - config.settings.skipAudits = SKIPPED_HTTPS_AUDITS; + 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}); }