diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5db822e..627fb21 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,7 +18,6 @@ npm link lighthouse-plugin-field-performance # add symlink to test the plugin lo npm run mobile-run https://www.apple.com/ # test plugin with a real PSI API response npm run desktop-run https://www.google.com/ -npm run mock-run # test UI with mock data ``` `lighthouse-plugin-field-performance` folder is made of symlinks for a simple local testing. diff --git a/package-lock.json b/package-lock.json index b18dfc7..5bcf952 100644 --- a/package-lock.json +++ b/package-lock.json @@ -385,42 +385,6 @@ "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==", "dev": true }, - "@sinonjs/commons": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.6.0.tgz", - "integrity": "sha512-w4/WHG7C4WWFyE5geCieFJF6MZkbW4VAriol5KlmQXpAQdxvV0p26sqNZOW6Qyw6Y0l9K4g+cHvvczR2sEEpqg==", - "dev": true, - "requires": { - "type-detect": "4.0.8" - } - }, - "@sinonjs/formatio": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.2.1.tgz", - "integrity": "sha512-tsHvOB24rvyvV2+zKMmPkZ7dXX6LSLKZ7aOtXY6Edklp0uRcgGpOsQTTGTcWViFyx4uhWc6GV8QdnALbIbIdeQ==", - "dev": true, - "requires": { - "@sinonjs/commons": "^1", - "@sinonjs/samsam": "^3.1.0" - } - }, - "@sinonjs/samsam": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.3.3.tgz", - "integrity": "sha512-bKCMKZvWIjYD0BLGnNrxVuw4dkWCYsLqFOUWw8VgKF/+5Y+mE7LfHWPIYoDXowH+3a9LsWDMo0uAP8YDosPvHQ==", - "dev": true, - "requires": { - "@sinonjs/commons": "^1.3.0", - "array-from": "^2.1.1", - "lodash": "^4.17.15" - } - }, - "@sinonjs/text-encoding": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz", - "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", - "dev": true - }, "@szmarczak/http-timer": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz", @@ -459,12 +423,6 @@ "integrity": "sha512-Fvm24+u85lGmV4hT5G++aht2C5I4Z4dYlWZIh62FAfFO/TfzXtPpoLI6I7AuBWkIFqZCnhFOoTT7RjjaIL5Fjg==", "dev": true }, - "@types/sinon": { - "version": "7.0.13", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-7.0.13.tgz", - "integrity": "sha512-d7c/C/+H/knZ3L8/cxhicHUiTDxdgap0b/aNJfsmLwFu/iOP17mdgbQsbHA3SJmrzsjD0l3UEE5SN4xxuz5ung==", - "dev": true - }, "JSV": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/JSV/-/JSV-4.0.2.tgz", @@ -583,12 +541,6 @@ "integrity": "sha1-3wEKoSh+Fku9pvlyOwqWoexBh6E=", "dev": true }, - "array-from": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/array-from/-/array-from-2.1.1.tgz", - "integrity": "sha1-z+nYwmYoudxa7MYqn12PHzUsEZU=", - "dev": true - }, "array-union": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", @@ -1551,12 +1503,6 @@ "integrity": "sha512-Sjg+A4q3Mrn2JKQu58zsreuHqAb4M0qe4eK5ZQAIBuch9i8nx6MlKWCxx0z8s59MMen9I4WXavzW5z+BnkIC0A==", "dev": true }, - "diff": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", - "dev": true - }, "dir-glob": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", @@ -2495,12 +2441,6 @@ "integrity": "sha512-VjSeb/lHmkoyd8ryPVIKvOCn4D1koMqY+vqyjjUfc3xyKtP4dYOxM44sZrnqQSzSds3xyOrUTLTC9LVCVgLngw==", "dev": true }, - "isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", - "dev": true - }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -2639,12 +2579,6 @@ "verror": "1.10.0" } }, - "just-extend": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.0.2.tgz", - "integrity": "sha512-FrLwOgm+iXrPV+5zDU6Jqu4gCRXbWEQg2O3SKONsWE4w7AXFRkryS53bpWdaL9cNol+AmR3AEYz6kn+o0fCPnw==", - "dev": true - }, "keyv": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz", @@ -3053,12 +2987,6 @@ "chalk": "^2.0.1" } }, - "lolex": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lolex/-/lolex-4.2.0.tgz", - "integrity": "sha512-gKO5uExCXvSm6zbF562EvM+rd1kQDnB9AZBbiQVzf1ZmdDpxUSvpnAaVOP83N/31mRK8Ml8/VE8DMvsAZQ+7wg==", - "dev": true - }, "lookup-closest-locale": { "version": "6.0.4", "resolved": "https://registry.npmjs.org/lookup-closest-locale/-/lookup-closest-locale-6.0.4.tgz", @@ -3295,19 +3223,6 @@ "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", "dev": true }, - "nise": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/nise/-/nise-1.5.2.tgz", - "integrity": "sha512-/6RhOUlicRCbE9s+94qCUsyE+pKlVJ5AhIv+jEE7ESKwnbXqulKZ1FYU+XAtHHWE9TinYvAxDUJAb912PwPoWA==", - "dev": true, - "requires": { - "@sinonjs/formatio": "^3.2.1", - "@sinonjs/text-encoding": "^0.7.1", - "just-extend": "^4.0.2", - "lolex": "^4.1.0", - "path-to-regexp": "^1.7.0" - } - }, "node-fetch": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", @@ -3630,15 +3545,6 @@ "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, - "path-to-regexp": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz", - "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=", - "dev": true, - "requires": { - "isarray": "0.0.1" - } - }, "path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", @@ -4257,32 +4163,6 @@ "resolved": "https://registry.npmjs.org/simple-format-number/-/simple-format-number-0.1.2.tgz", "integrity": "sha1-XiotAXlxzeqeIkYZk8cxBr2atno=" }, - "sinon": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-7.4.2.tgz", - "integrity": "sha512-pY5RY99DKelU3pjNxcWo6XqeB1S118GBcVIIdDi6V+h6hevn1izcg2xv1hTHW/sViRXU7sUOxt4wTUJ3gsW2CQ==", - "dev": true, - "requires": { - "@sinonjs/commons": "^1.4.0", - "@sinonjs/formatio": "^3.2.1", - "@sinonjs/samsam": "^3.3.3", - "diff": "^3.5.0", - "lolex": "^4.2.0", - "nise": "^1.5.2", - "supports-color": "^5.5.0" - }, - "dependencies": { - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - } - } - }, "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -4653,12 +4533,6 @@ "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", "dev": true }, - "type-detect": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true - }, "type-fest": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.5.2.tgz", diff --git a/package.json b/package.json index 213f7ed..bd267a5 100644 --- a/package.json +++ b/package.json @@ -40,11 +40,9 @@ }, "devDependencies": { "@types/node": "10", - "@types/sinon": "^7.0.13", "ava": "^2.3.0", "lighthouse": "^5.2.0", "prettier": "^1.18.2", - "sinon": "^7.4.2", "typescript": "^3.6.3" } } diff --git a/test/fixtures/load-experience-not-in-crux.json b/test/fixtures/load-experience-not-in-crux.json deleted file mode 100644 index 3546402..0000000 --- a/test/fixtures/load-experience-not-in-crux.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "loadingExperience": { - "initial_url": "https://example.com/" - }, - "originLoadingExperience": null -} diff --git a/test/fixtures/load-experience.json b/test/fixtures/load-experience.json deleted file mode 100644 index 0ad8e2f..0000000 --- a/test/fixtures/load-experience.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "loadingExperience": { - "id": "https://www.bbc.com/news", - "metrics": { - "FIRST_INPUT_DELAY_MS": { - "percentile": 46, - "distributions": [ - { - "min": 0, - "max": 50, - "proportion": 0.9534172576269574 - }, - { - "min": 50, - "max": 250, - "proportion": 0.03711151301699111 - }, - { - "min": 250, - "proportion": 0.009471229356051592 - } - ], - "category": "FAST" - }, - "FIRST_CONTENTFUL_PAINT_MS": { - "percentile": 2443, - "distributions": [ - { - "min": 0, - "max": 1000, - "proportion": 0.6159602703883568 - }, - { - "min": 1000, - "max": 2500, - "proportion": 0.28729123874428114 - }, - { - "min": 2500, - "proportion": 0.09674849086736212 - } - ], - "category": "AVERAGE" - } - }, - "overall_category": "AVERAGE", - "initial_url": "https://www.bbc.com/news" - }, - "originLoadingExperience": { - "id": "https://www.bbc.com", - "metrics": { - "FIRST_INPUT_DELAY_MS": { - "percentile": 224, - "distributions": [ - { - "min": 0, - "max": 50, - "proportion": 0.8710104890102028 - }, - { - "min": 50, - "max": 250, - "proportion": 0.0837502889155486 - }, - { - "min": 250, - "proportion": 0.04523922207424855 - } - ], - "category": "AVERAGE" - }, - "FIRST_CONTENTFUL_PAINT_MS": { - "percentile": 3125, - "distributions": [ - { - "min": 0, - "max": 1000, - "proportion": 0.5073388657747151 - }, - { - "min": 1000, - "max": 2500, - "proportion": 0.34307981092253487 - }, - { - "min": 2500, - "proportion": 0.14958132330274995 - } - ], - "category": "SLOW" - } - }, - "overall_category": "SLOW", - "initial_url": "https://www.bbc.com/news" - } -} diff --git a/test/index.js b/test/index.js index 663e97a..e401785 100644 --- a/test/index.js +++ b/test/index.js @@ -1,16 +1,13 @@ const { serial } = require('ava') const { readFileSync } = require('fs') const { join } = require('path') -const sinon = require('sinon') const { runLighthouse } = require('lighthouse/lighthouse-cli/run') -const psi = require('../src/utils/run-psi') -const loadExperienceInCrUX = require('./fixtures/load-experience.json') -const loadExperienceNotInCrUX = require('./fixtures/load-experience-not-in-crux.json') const lhOptions = { output: ['json'], outputPath: './results/test-results.json', chromeFlags: '--headless --enable-logging --no-sandbox', + onlyCategories: ['lighthouse-plugin-field-performance'], plugins: ['lighthouse-plugin-field-performance'] } @@ -19,16 +16,10 @@ const getTestResults = resName => { return JSON.parse(readFileSync(join(__dirname, '../results', resName), 'utf8')) } -sinon - .stub(psi, 'runPsi') - .onFirstCall() - .returns(Promise.resolve(loadExperienceInCrUX)) - .onSecondCall() - .returns(Promise.resolve(loadExperienceNotInCrUX)) - serial('Measure field perf for site in CruX', async t => { const resName = 'in-field.json' - await runLighthouse('https://google.com/', { ...lhOptions, outputPath: `./results/${resName}` }) + await runLighthouse('https://example.com/', { ...lhOptions, outputPath: `./results/${resName}` }) + // FIXME: don't snapshot numeric values const { audits, categories } = getTestResults(resName) t.snapshot(audits['field-fcp']) t.snapshot(audits['field-fid']) @@ -39,7 +30,7 @@ serial('Measure field perf for site in CruX', async t => { serial('Measure field perf for site site not in CruX', async t => { const resName = 'not-in-field.json' - await runLighthouse('https://example.com/', { ...lhOptions, outputPath: `./results/${resName}` }) + await runLighthouse('https://alekseykulikov.com/', { ...lhOptions, outputPath: `./results/${resName}` }) const { audits, categories } = getTestResults(resName) t.snapshot(audits['field-fcp']) diff --git a/test/mock-run.js b/test/mock-run.js deleted file mode 100644 index 3eaf2cc..0000000 --- a/test/mock-run.js +++ /dev/null @@ -1,32 +0,0 @@ -const { runLighthouse } = require('lighthouse/lighthouse-cli/run') -const sinon = require('sinon') -const psi = require('../src/utils/run-psi') -const data = require('./fixtures/load-experience.json') - -const config = { - extends: 'lighthouse:default' - // settings: { - // psiToken: '0123456789' - // } -} - -;(async () => { - try { - sinon.stub(psi, 'runPsi').returns(Promise.resolve(data)) - await runLighthouse( - 'https://www.bbc.com/news', - { - output: ['html'], - outputPath: './results/bbc.com.html', - view: true, - plugins: ['lighthouse-plugin-field-performance'], - chromeFlags: '--headless' - }, - config - ) - process.exit(0) - } catch (e) { - console.log(e) - process.exit(1) - } -})() diff --git a/test/snapshots/test/index.js.md b/test/snapshots/test/index.js.md index 2ef2e5d..38a62a2 100644 --- a/test/snapshots/test/index.js.md +++ b/test/snapshots/test/index.js.md @@ -26,11 +26,11 @@ Generated by [AVA](https://ava.li). items: [ { category: 'Fast (faster than 1 s)', - distribution: '62 %', + distribution: '58 %', }, { category: 'Average (from 1 s to 2.5 s)', - distribution: '29 %', + distribution: '32 %', }, { category: 'Slow (longer than 2.5 s)', @@ -39,10 +39,10 @@ Generated by [AVA](https://ava.li). ], type: 'table', }, - displayValue: '2.4 s', + displayValue: '2.5 s', id: 'field-fcp', - numericValue: 2443, - score: 0.52, + numericValue: 2544, + score: 0.49, scoreDisplayMode: 'numeric', title: 'First Contentful Paint (URL)', } @@ -67,11 +67,11 @@ Generated by [AVA](https://ava.li). items: [ { category: 'Fast (faster than 50 ms)', - distribution: '95 %', + distribution: '93 %', }, { category: 'Average (from 50 ms to 250 ms)', - distribution: '4 %', + distribution: '5 %', }, { category: 'Slow (longer than 250 ms)', @@ -80,10 +80,10 @@ Generated by [AVA](https://ava.li). ], type: 'table', }, - displayValue: '50 ms', + displayValue: '120 ms', id: 'field-fid', - numericValue: 46, - score: 0.99, + numericValue: 122, + score: 0.83, scoreDisplayMode: 'numeric', title: 'First Input Delay (URL)', } @@ -108,23 +108,23 @@ Generated by [AVA](https://ava.li). items: [ { category: 'Fast (faster than 1 s)', - distribution: '51 %', + distribution: '57 %', }, { category: 'Average (from 1 s to 2.5 s)', - distribution: '34 %', + distribution: '32 %', }, { category: 'Slow (longer than 2.5 s)', - distribution: '15 %', + distribution: '11 %', }, ], type: 'table', }, - displayValue: '3.1 s', + displayValue: '2.6 s', id: 'field-fcp-origin', - numericValue: 3125, - score: 0.33, + numericValue: 2563, + score: 0.48, scoreDisplayMode: 'numeric', title: 'First Contentful Paint (Origin)', } @@ -149,23 +149,23 @@ Generated by [AVA](https://ava.li). items: [ { category: 'Fast (faster than 50 ms)', - distribution: '87 %', + distribution: '93 %', }, { category: 'Average (from 50 ms to 250 ms)', - distribution: '8 %', + distribution: '5 %', }, { category: 'Slow (longer than 250 ms)', - distribution: '5 %', + distribution: '1 %', }, ], type: 'table', }, - displayValue: '220 ms', + displayValue: '110 ms', id: 'field-fid-origin', - numericValue: 224, - score: 0.56, + numericValue: 112, + score: 0.86, scoreDisplayMode: 'numeric', title: 'First Input Delay (Origin)', } @@ -197,7 +197,7 @@ Generated by [AVA](https://ava.li). ], description: 'These metrics show the performance of the page for real-world Chrome users over the last 30 days. Data is collected anonymously in the "field" and provided by Chrome UX Report. [Learn More](https://developers.google.com/web/tools/chrome-user-experience-report/)', id: 'lighthouse-plugin-field-performance', - score: 0.76, + score: 0.66, title: 'Field Performance', } diff --git a/test/snapshots/test/index.js.snap b/test/snapshots/test/index.js.snap index de21e6b..065130d 100644 Binary files a/test/snapshots/test/index.js.snap and b/test/snapshots/test/index.js.snap differ diff --git a/tsconfig.json b/tsconfig.json index 1a1e65b..ea04b1d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "allowJs": true, "checkJs": true, "strict": true, + "strictNullChecks": true, "resolveJsonModule": true, "noUnusedLocals": true, "noUnusedParameters": true