From 52f42e4b8f9e1abf21b6d7b7ff27b7bc25105b2e Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Wed, 15 Mar 2017 10:54:15 +1100 Subject: [PATCH] Easy serviceworker testing config. To run: yarn sw -- http://caltrainschedule.io --output=json --- .eslintignore | 1 + lighthouse-core/audits/service-worker.js | 9 ++++- lighthouse-core/config/sw.json | 44 ++++++++++++++++++++++++ package.json | 1 + 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 lighthouse-core/config/sw.json diff --git a/.eslintignore b/.eslintignore index 450f00488c2f..3911ca47c96f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -21,3 +21,4 @@ lighthouse-cli/types/*.js # Handlebar-templates lighthouse-core/report/templates/report-templates.js lighthouse-core/report/partials/templates/report-partials.js +lighthouse-core/formatters/partials/templates/report-partials.js diff --git a/lighthouse-core/audits/service-worker.js b/lighthouse-core/audits/service-worker.js index e923575b5e88..8e8e70502135 100644 --- a/lighthouse-core/audits/service-worker.js +++ b/lighthouse-core/audits/service-worker.js @@ -20,6 +20,8 @@ const URL = require('../lib/url-shim'); const Audit = require('./audit'); +const Formatter = require('../report/formatter'); + /** * @param {!Array} versions * @param {string} url @@ -56,8 +58,13 @@ class ServiceWorker extends Audit { const version = getActivatedServiceWorker( artifacts.ServiceWorker.versions, artifacts.URL.finalUrl); + return { - rawValue: !!version + rawValue: !!version, + extendedInfo: { + formatter: Formatter.SUPPORTED_FORMATS.NULL, + value: artifacts.ServiceWorker.versions + } }; } } diff --git a/lighthouse-core/config/sw.json b/lighthouse-core/config/sw.json new file mode 100644 index 000000000000..a91106d42efa --- /dev/null +++ b/lighthouse-core/config/sw.json @@ -0,0 +1,44 @@ +{ + "passes": [{ + "passName": "defaultPass", + "recordNetwork": true, + "useThrottling": false, + "gatherers": [ + "url" + ] + }, + { + "passName": "offlinePass", + "recordNetwork": true, + "useThrottling": false, + "gatherers": [ + "service-worker", + "offline" + ] + } + ], + + "audits": [ + "service-worker", + "works-offline" + ], + + "aggregations": [{ + "name": "Service Worker State", + "description": "", + "scored": false, + "categorizable": false, + "items": [{ + "audits": { + "service-worker": { + "expectedValue": true, + "weight": 1 + }, + "works-offline": { + "expectedValue": true, + "weight": 1 + } + } + }] + }] +} diff --git a/package.json b/package.json index e074e9b86fb5..1bc35b440713 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "watch": "bash lighthouse-core/scripts/run-mocha.sh --watch", "chrome": "node ./lighthouse-cli/manual-chrome-launcher.js", "fast": "npm run start -- --disable-device-emulation --disable-cpu-throttling --disable-network-throttling", + "sw": "npm run start -- --disable-cpu-throttling --disable-network-throttling --config-path=./lighthouse-core/config/sw.json", "smokehouse": "node lighthouse-cli/test/smokehouse/smokehouse.js", "deploy-viewer": "cd lighthouse-viewer && gulp deploy" },