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
This commit is contained in:
parent
ca9b3eed9e
commit
60e9d2da4f
|
@ -249,10 +249,7 @@ jobs:
|
||||||
- run: yarn --cwd aio lint
|
- run: yarn --cwd aio lint
|
||||||
# Run PWA-score tests
|
# Run PWA-score tests
|
||||||
# (Run before unit and e2e tests, which destroy the `dist/` directory.)
|
# (Run before unit and e2e tests, which destroy the `dist/` directory.)
|
||||||
# Temporarily lowering the min required PWA score to avoid flakes on CI.
|
- run: yarn --cwd aio test-pwa-score-localhost $CI_AIO_MIN_PWA_SCORE
|
||||||
# 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
|
|
||||||
# Check the bundle sizes.
|
# Check the bundle sizes.
|
||||||
# (Run before unit and e2e tests, which destroy the `dist/` directory.)
|
# (Run before unit and e2e tests, which destroy the `dist/` directory.)
|
||||||
- run: yarn --cwd aio payload-size
|
- run: yarn --cwd aio payload-size
|
||||||
|
@ -287,10 +284,7 @@ jobs:
|
||||||
- run: yarn --cwd aio build-local --progress=false
|
- run: yarn --cwd aio build-local --progress=false
|
||||||
# Run PWA-score tests
|
# Run PWA-score tests
|
||||||
# (Run before unit and e2e tests, which destroy the `dist/` directory.)
|
# (Run before unit and e2e tests, which destroy the `dist/` directory.)
|
||||||
# Temporarily lowering the min required PWA score to avoid flakes on CI.
|
- run: yarn --cwd aio test-pwa-score-localhost $CI_AIO_MIN_PWA_SCORE
|
||||||
# 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 unit tests
|
# Run unit tests
|
||||||
- run: yarn --cwd aio test --progress=false --watch=false
|
- run: yarn --cwd aio test --progress=false --watch=false
|
||||||
# Run e2e tests
|
# Run e2e tests
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
const chromeLauncher = require('chrome-launcher');
|
const chromeLauncher = require('chrome-launcher');
|
||||||
const lighthouse = require('lighthouse');
|
const lighthouse = require('lighthouse');
|
||||||
const printer = require('lighthouse/lighthouse-cli/printer');
|
const printer = require('lighthouse/lighthouse-cli/printer');
|
||||||
const config = require('lighthouse/lighthouse-core/config/default-config.js');
|
|
||||||
const logger = require('lighthouse-logger');
|
const logger = require('lighthouse-logger');
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const CHROME_LAUNCH_OPTS = {};
|
const CHROME_LAUNCH_OPTS = {};
|
||||||
const LIGHTHOUSE_FLAGS = {logLevel: 'info'};
|
const LIGHTHOUSE_FLAGS = {logLevel: 'info'};
|
||||||
|
const LONG_WAIT_FOR_SW_DELAY = 5000;
|
||||||
const SKIPPED_HTTPS_AUDITS = ['redirects-http'];
|
const SKIPPED_HTTPS_AUDITS = ['redirects-http'];
|
||||||
const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/';
|
const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/';
|
||||||
|
|
||||||
|
@ -37,12 +37,18 @@ _main(process.argv.slice(2));
|
||||||
async function _main(args) {
|
async function _main(args) {
|
||||||
const {url, minScore, logFile} = parseInput(args);
|
const {url, minScore, logFile} = parseInput(args);
|
||||||
const isOnHttp = /^http:/.test(url);
|
const isOnHttp = /^http:/.test(url);
|
||||||
|
const isOnLocalhost = /\/\/localhost\b/.test(url);
|
||||||
|
const config = {extends: 'lighthouse:default'};
|
||||||
|
|
||||||
console.log(`Running PWA audit for '${url}'...`);
|
console.log(`Running PWA audit for '${url}'...`);
|
||||||
|
|
||||||
if (isOnHttp) {
|
// If testing on HTTP, skip HTTPS-specific tests.
|
||||||
skipHttpsAudits(config);
|
// (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);
|
logger.setLevel(LIGHTHOUSE_FLAGS.logLevel);
|
||||||
|
|
||||||
|
@ -124,5 +130,12 @@ async function processResults(results, logFile) {
|
||||||
|
|
||||||
function skipHttpsAudits(config) {
|
function skipHttpsAudits(config) {
|
||||||
console.info(`Skipping HTTPS-related audits (${SKIPPED_HTTPS_AUDITS.join(', ')})...`);
|
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});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue