lighthouse 8.6.0-dev.20211029 → 8.6.0-dev.20211102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/report/flow.js +14 -14
- package/dist/report/standalone.js +12 -12
- package/flow-report/.eslintrc.cjs +2 -0
- package/flow-report/assets/styles.css +1 -1
- package/flow-report/src/app.tsx +10 -11
- package/flow-report/src/common.tsx +22 -9
- package/flow-report/src/header.tsx +3 -3
- package/flow-report/src/i18n/i18n.tsx +10 -6
- package/flow-report/src/icons.tsx +21 -9
- package/flow-report/src/sidebar/flow.tsx +3 -3
- package/flow-report/src/sidebar/sidebar.tsx +12 -6
- package/flow-report/src/summary/category.tsx +9 -4
- package/flow-report/src/summary/summary.tsx +9 -3
- package/flow-report/src/util.ts +31 -19
- package/flow-report/src/wrappers/report-renderer.tsx +9 -3
- package/flow-report/src/wrappers/report.tsx +17 -7
- package/flow-report/test/common-test.tsx +25 -10
- package/flow-report/test/header-test.tsx +6 -6
- package/flow-report/test/setup/env-setup.ts +1 -1
- package/flow-report/test/summary/category-test.tsx +5 -5
- package/flow-report/test/util-test.tsx +32 -11
- package/lighthouse-cli/.eslintrc.cjs +2 -0
- package/lighthouse-cli/cli-flags.js +1 -1
- package/lighthouse-cli/test/smokehouse/lighthouse-runners/bundle.js +4 -2
- package/lighthouse-cli/test/smokehouse/smokehouse.js +1 -1
- package/lighthouse-core/audits/audit.js +1 -1
- package/lighthouse-core/computed/metrics/lantern-total-blocking-time.js +3 -4
- package/lighthouse-core/computed/metrics/tbt-utils.js +57 -0
- package/lighthouse-core/computed/metrics/total-blocking-time.js +3 -53
- package/lighthouse-core/computed/resource-summary.js +1 -1
- package/lighthouse-core/config/config-helpers.js +20 -10
- package/lighthouse-core/config/default-config.js +59 -55
- package/lighthouse-core/fraggle-rock/config/default-config.js +1 -1
- package/lighthouse-core/fraggle-rock/gather/base-gatherer.js +6 -1
- package/lighthouse-core/gather/connections/cri.js +1 -1
- package/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js +1 -0
- package/lighthouse-core/lib/asset-saver.js +4 -1
- package/lighthouse-core/lib/lh-env.js +2 -0
- package/lighthouse-core/lib/proto-preprocessor.js +14 -2
- package/lighthouse-core/lib/tappable-rects.js +8 -15
- package/lighthouse-core/lib/url-shim.js +1 -1
- package/lighthouse-core/runner.js +1 -1
- package/lighthouse-core/util-commonjs.js +25 -11
- package/package.json +11 -8
- package/report/.eslintrc.cjs +2 -0
- package/report/assets/styles.css +226 -250
- package/report/assets/templates.html +19 -29
- package/report/clients/standalone.js +0 -2
- package/report/renderer/category-renderer.js +21 -17
- package/report/renderer/components.js +21 -54
- package/report/renderer/crc-details-renderer.js +15 -12
- package/report/renderer/element-screenshot-renderer.js +2 -2
- package/report/renderer/open-tab.js +9 -3
- package/report/renderer/performance-category-renderer.js +51 -24
- package/report/renderer/report-renderer.js +2 -1
- package/report/renderer/report-ui-features.js +2 -3
- package/report/renderer/util.js +26 -11
- package/report/test/renderer/category-renderer-test.js +2 -2
- package/report/test/renderer/performance-category-renderer-test.js +35 -9
- package/report/test/renderer/report-renderer-test.js +1 -1
- package/report/test/renderer/report-ui-features-test.js +10 -9
- package/report/test/renderer/util-test.js +13 -31
- package/report/test-assets/faux-psi.js +5 -5
- package/shared/localization/format.js +9 -4
- package/shared/localization/locales/ar-XB.json +0 -15
- package/shared/localization/locales/ar.json +0 -15
- package/shared/localization/locales/bg.json +0 -15
- package/shared/localization/locales/ca.json +0 -15
- package/shared/localization/locales/cs.json +0 -15
- package/shared/localization/locales/da.json +0 -15
- package/shared/localization/locales/de.json +0 -15
- package/shared/localization/locales/el.json +0 -15
- package/shared/localization/locales/en-GB.json +0 -15
- package/shared/localization/locales/en-US.json +19 -16
- package/shared/localization/locales/en-XA.json +0 -15
- package/shared/localization/locales/en-XL.json +19 -16
- package/shared/localization/locales/es-419.json +0 -15
- package/shared/localization/locales/es.json +0 -15
- package/shared/localization/locales/fi.json +0 -15
- package/shared/localization/locales/fil.json +0 -15
- package/shared/localization/locales/fr.json +0 -15
- package/shared/localization/locales/he.json +0 -15
- package/shared/localization/locales/hi.json +0 -15
- package/shared/localization/locales/hr.json +0 -15
- package/shared/localization/locales/hu.json +0 -15
- package/shared/localization/locales/id.json +0 -15
- package/shared/localization/locales/it.json +0 -15
- package/shared/localization/locales/ja.json +0 -15
- package/shared/localization/locales/ko.json +0 -15
- package/shared/localization/locales/lt.json +0 -15
- package/shared/localization/locales/lv.json +0 -15
- package/shared/localization/locales/nl.json +0 -15
- package/shared/localization/locales/no.json +0 -15
- package/shared/localization/locales/pl.json +0 -15
- package/shared/localization/locales/pt-PT.json +0 -15
- package/shared/localization/locales/pt.json +0 -15
- package/shared/localization/locales/ro.json +0 -15
- package/shared/localization/locales/ru.json +0 -15
- package/shared/localization/locales/sk.json +0 -15
- package/shared/localization/locales/sl.json +0 -15
- package/shared/localization/locales/sr-Latn.json +0 -15
- package/shared/localization/locales/sr.json +0 -15
- package/shared/localization/locales/sv.json +0 -15
- package/shared/localization/locales/ta.json +0 -15
- package/shared/localization/locales/te.json +0 -15
- package/shared/localization/locales/th.json +0 -15
- package/shared/localization/locales/tr.json +0 -15
- package/shared/localization/locales/uk.json +0 -15
- package/shared/localization/locales/vi.json +0 -15
- package/shared/localization/locales/zh-HK.json +0 -15
- package/shared/localization/locales/zh-TW.json +0 -15
- package/shared/localization/locales/zh.json +0 -15
- package/third-party/chromium-synchronization/installability-errors-test.js +2 -0
- package/types/lhr/flow.d.ts +3 -2
- package/types/rollup-plugin-postprocess.d.ts +10 -0
- package/lighthouse-core/audits/dobetterweb/external-anchors-use-rel-noopener.js +0 -96
|
@@ -24,10 +24,19 @@ describe('FlowStepThumbnail', () => {
|
|
|
24
24
|
'full-page-screenshot': {
|
|
25
25
|
details: {
|
|
26
26
|
type: 'full-page-screenshot',
|
|
27
|
-
screenshot: {data: '
|
|
27
|
+
screenshot: {data: 'FPS', width: 400, height: 600},
|
|
28
28
|
nodes: {},
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
|
+
'screenshot-thumbnails': {
|
|
32
|
+
details: {
|
|
33
|
+
type: 'filmstrip',
|
|
34
|
+
items: [
|
|
35
|
+
{data: 'frame1'},
|
|
36
|
+
{data: 'frame2'},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
},
|
|
31
40
|
},
|
|
32
41
|
} as any;
|
|
33
42
|
});
|
|
@@ -63,17 +72,23 @@ describe('FlowStepThumbnail', () => {
|
|
|
63
72
|
expect(thumbnail.style.height).toEqual('150px');
|
|
64
73
|
});
|
|
65
74
|
|
|
75
|
+
it('uses last filmstrip thumbnail', () => {
|
|
76
|
+
const root = render(<FlowStepThumbnail lhr={lhr} height={150} />);
|
|
77
|
+
|
|
78
|
+
const thumbnail = root.getByAltText(/Screenshot/) as HTMLImageElement;
|
|
79
|
+
expect(thumbnail.src).toContain('frame2');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('uses full page screenshot if filmstrip unavailable', () => {
|
|
83
|
+
delete lhr.audits['screenshot-thumbnails'];
|
|
84
|
+
const root = render(<FlowStepThumbnail lhr={lhr} height={150} />);
|
|
85
|
+
|
|
86
|
+
const thumbnail = root.getByAltText(/Screenshot/) as HTMLImageElement;
|
|
87
|
+
expect(thumbnail.src).toContain('FPS');
|
|
88
|
+
});
|
|
89
|
+
|
|
66
90
|
it('renders animated thumbnail for timespan', async () => {
|
|
67
91
|
lhr.gatherMode = 'timespan';
|
|
68
|
-
lhr.audits['screenshot-thumbnails'] = {
|
|
69
|
-
details: {
|
|
70
|
-
type: 'filmstrip',
|
|
71
|
-
items: [
|
|
72
|
-
{data: 'frame1'},
|
|
73
|
-
{data: 'frame2'},
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
} as any;
|
|
77
92
|
const root = render(<FlowStepThumbnail lhr={lhr} height={150} />);
|
|
78
93
|
|
|
79
94
|
const thumbnail = root.getByAltText(/Animated/) as HTMLImageElement;
|
|
@@ -25,8 +25,8 @@ beforeEach(() => {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
it('renders all sections for a middle step', () => {
|
|
28
|
-
const
|
|
29
|
-
const root = render(<Header
|
|
28
|
+
const hashState = {index: 1} as any;
|
|
29
|
+
const root = render(<Header hashState={hashState}/>, {wrapper});
|
|
30
30
|
|
|
31
31
|
expect(root.baseElement.querySelector('.Header__prev-thumbnail')).toBeTruthy();
|
|
32
32
|
expect(root.baseElement.querySelector('.Header__prev-title')).toBeTruthy();
|
|
@@ -35,8 +35,8 @@ it('renders all sections for a middle step', () => {
|
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
it('renders only next section for first step', () => {
|
|
38
|
-
const
|
|
39
|
-
const root = render(<Header
|
|
38
|
+
const hashState = {index: 0} as any;
|
|
39
|
+
const root = render(<Header hashState={hashState}/>, {wrapper});
|
|
40
40
|
|
|
41
41
|
expect(root.baseElement.querySelector('.Header__prev-thumbnail')).toBeFalsy();
|
|
42
42
|
expect(root.baseElement.querySelector('.Header__prev-title')).toBeFalsy();
|
|
@@ -45,8 +45,8 @@ it('renders only next section for first step', () => {
|
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
it('renders only previous section for last step', () => {
|
|
48
|
-
const
|
|
49
|
-
const root = render(<Header
|
|
48
|
+
const hashState = {index: 3} as any;
|
|
49
|
+
const root = render(<Header hashState={hashState}/>, {wrapper});
|
|
50
50
|
|
|
51
51
|
expect(root.baseElement.querySelector('.Header__prev-thumbnail')).toBeTruthy();
|
|
52
52
|
expect(root.baseElement.querySelector('.Header__prev-title')).toBeTruthy();
|
|
@@ -10,7 +10,7 @@ import {JSDOM} from 'jsdom';
|
|
|
10
10
|
/**
|
|
11
11
|
* The jest environment "jsdom" does not work when preact is combined with the report renderer.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
function setupJsDom() {
|
|
14
14
|
const {window} = new JSDOM(undefined, {
|
|
15
15
|
url: 'file:///Users/example/report.html/',
|
|
16
16
|
});
|
|
@@ -51,7 +51,7 @@ describe('SummaryTooltip', () => {
|
|
|
51
51
|
expect(() => root.getByText(/^[0-9]+$/)).toThrow();
|
|
52
52
|
expect(root.getByText('2 audits passed')).toBeTruthy();
|
|
53
53
|
expect(root.getByText('3 passable audits')).toBeTruthy();
|
|
54
|
-
expect(root.getByText('https://example.com'));
|
|
54
|
+
expect(root.getByText('https://example.com')).toBeTruthy();
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
it('renders tooltip without rating', async () => {
|
|
@@ -76,7 +76,7 @@ describe('SummaryTooltip', () => {
|
|
|
76
76
|
expect(() => root.getByText(/^[0-9]+$/)).toThrow();
|
|
77
77
|
expect(root.getByText('2 audits passed')).toBeTruthy();
|
|
78
78
|
expect(root.getByText('3 passable audits')).toBeTruthy();
|
|
79
|
-
expect(root.getByText('https://example.com'));
|
|
79
|
+
expect(root.getByText('https://example.com')).toBeTruthy();
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
it('renders scored category tooltip with score', async () => {
|
|
@@ -101,7 +101,7 @@ describe('SummaryTooltip', () => {
|
|
|
101
101
|
expect(root.getByText('100')).toBeTruthy();
|
|
102
102
|
expect(root.getByText('2 audits passed')).toBeTruthy();
|
|
103
103
|
expect(root.getByText('3 passable audits')).toBeTruthy();
|
|
104
|
-
expect(root.getByText('https://example.com'));
|
|
104
|
+
expect(root.getByText('https://example.com')).toBeTruthy();
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
it('renders informative audit count if any', async () => {
|
|
@@ -127,7 +127,7 @@ describe('SummaryTooltip', () => {
|
|
|
127
127
|
expect(root.getByText('2 audits passed')).toBeTruthy();
|
|
128
128
|
expect(root.getByText('2 passable audits')).toBeTruthy();
|
|
129
129
|
expect(root.getByText('1 informative audit')).toBeTruthy();
|
|
130
|
-
expect(root.getByText('https://example.com'));
|
|
130
|
+
expect(root.getByText('https://example.com')).toBeTruthy();
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
it('renders highest impact audits', async () => {
|
|
@@ -192,7 +192,7 @@ describe('SummaryTooltip', () => {
|
|
|
192
192
|
auditRefs: [
|
|
193
193
|
/* eslint-disable max-len */
|
|
194
194
|
{result: {score: 1, scoreDisplayMode: 'binary', title: 'Audit 1'}, weight: 1, group: 'diagnostics'},
|
|
195
|
-
{result: {score: 0, scoreDisplayMode: 'binary', title: 'Audit 2'}, weight: 1},
|
|
195
|
+
{result: {score: 0, scoreDisplayMode: 'binary', title: 'Audit 2'}, weight: 1, group: 'hidden'},
|
|
196
196
|
{result: {score: null, scoreDisplayMode: 'informative', title: 'Audit 3'}, weight: 1, group: 'diagnostics'},
|
|
197
197
|
/* eslint-enable max-len */
|
|
198
198
|
],
|
|
@@ -9,7 +9,7 @@ import {renderHook} from '@testing-library/preact-hooks';
|
|
|
9
9
|
import {FunctionComponent} from 'preact';
|
|
10
10
|
import {act} from 'preact/test-utils';
|
|
11
11
|
|
|
12
|
-
import {FlowResultContext,
|
|
12
|
+
import {FlowResultContext, useHashState} from '../src/util';
|
|
13
13
|
import {flowResult} from './sample-flow';
|
|
14
14
|
|
|
15
15
|
let wrapper: FunctionComponent;
|
|
@@ -21,54 +21,75 @@ beforeEach(() => {
|
|
|
21
21
|
);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
describe('
|
|
24
|
+
describe('useHashState', () => {
|
|
25
25
|
it('gets current lhr index from url hash', () => {
|
|
26
26
|
global.location.hash = '#index=1';
|
|
27
|
-
const {result} = renderHook(() =>
|
|
27
|
+
const {result} = renderHook(() => useHashState(), {wrapper});
|
|
28
28
|
expect(console.warn).not.toHaveBeenCalled();
|
|
29
29
|
expect(result.current).toEqual({
|
|
30
30
|
index: 1,
|
|
31
|
-
|
|
31
|
+
currentLhr: flowResult.steps[1].lhr,
|
|
32
|
+
anchor: null,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('gets anchor id from url hash', () => {
|
|
37
|
+
global.location.hash = '#index=1&anchor=seo';
|
|
38
|
+
const {result} = renderHook(() => useHashState(), {wrapper});
|
|
39
|
+
expect(console.warn).not.toHaveBeenCalled();
|
|
40
|
+
expect(result.current).toEqual({
|
|
41
|
+
index: 1,
|
|
42
|
+
currentLhr: flowResult.steps[1].lhr,
|
|
43
|
+
anchor: 'seo',
|
|
32
44
|
});
|
|
33
45
|
});
|
|
34
46
|
|
|
35
47
|
it('changes on navigation', async () => {
|
|
36
48
|
global.location.hash = '#index=1';
|
|
37
|
-
const render = renderHook(() =>
|
|
49
|
+
const render = renderHook(() => useHashState(), {wrapper});
|
|
38
50
|
|
|
39
51
|
expect(render.result.current).toEqual({
|
|
40
52
|
index: 1,
|
|
41
|
-
|
|
53
|
+
currentLhr: flowResult.steps[1].lhr,
|
|
54
|
+
anchor: null,
|
|
42
55
|
});
|
|
43
56
|
|
|
44
57
|
await act(() => {
|
|
45
|
-
global.location.hash = '#index=2';
|
|
58
|
+
global.location.hash = '#index=2&anchor=seo';
|
|
46
59
|
});
|
|
47
60
|
await render.waitForNextUpdate();
|
|
48
61
|
|
|
49
62
|
expect(console.warn).not.toHaveBeenCalled();
|
|
50
63
|
expect(render.result.current).toEqual({
|
|
51
64
|
index: 2,
|
|
52
|
-
|
|
65
|
+
currentLhr: flowResult.steps[2].lhr,
|
|
66
|
+
anchor: 'seo',
|
|
53
67
|
});
|
|
54
68
|
});
|
|
55
69
|
|
|
56
70
|
it('return null if lhr index is unset', () => {
|
|
57
|
-
const {result} = renderHook(() =>
|
|
71
|
+
const {result} = renderHook(() => useHashState(), {wrapper});
|
|
58
72
|
expect(console.warn).not.toHaveBeenCalled();
|
|
59
73
|
expect(result.current).toBeNull();
|
|
60
74
|
});
|
|
61
75
|
|
|
62
76
|
it('return null if lhr index is out of bounds', () => {
|
|
63
77
|
global.location.hash = '#index=5';
|
|
64
|
-
const {result} = renderHook(() =>
|
|
78
|
+
const {result} = renderHook(() => useHashState(), {wrapper});
|
|
65
79
|
expect(console.warn).toHaveBeenCalled();
|
|
66
80
|
expect(result.current).toBeNull();
|
|
67
81
|
});
|
|
68
82
|
|
|
69
83
|
it('returns null for invalid value', () => {
|
|
70
84
|
global.location.hash = '#index=OHNO';
|
|
71
|
-
const {result} = renderHook(() =>
|
|
85
|
+
const {result} = renderHook(() => useHashState(), {wrapper});
|
|
86
|
+
expect(console.warn).toHaveBeenCalled();
|
|
87
|
+
expect(result.current).toBeNull();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('returns null for invalid value with valid anchor', () => {
|
|
91
|
+
global.location.hash = '#index=OHNO&anchor=seo';
|
|
92
|
+
const {result} = renderHook(() => useHashState(), {wrapper});
|
|
72
93
|
expect(console.warn).toHaveBeenCalled();
|
|
73
94
|
expect(result.current).toBeNull();
|
|
74
95
|
});
|
|
@@ -11,9 +11,12 @@
|
|
|
11
11
|
* Currently uses `lighthouse-dt-bundle.js`.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import fs from 'fs';
|
|
15
|
+
|
|
14
16
|
import ChromeLauncher from 'chrome-launcher';
|
|
15
17
|
|
|
16
18
|
import ChromeProtocol from '../../../../lighthouse-core/gather/connections/cri.js';
|
|
19
|
+
import {LH_ROOT} from '../../../../root.js';
|
|
17
20
|
|
|
18
21
|
const originalRequire = global.require;
|
|
19
22
|
if (typeof globalThis === 'undefined') {
|
|
@@ -22,8 +25,7 @@ if (typeof globalThis === 'undefined') {
|
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
// Load bundle, which creates a `global.runBundledLighthouse`.
|
|
25
|
-
|
|
26
|
-
import '../../../../dist/lighthouse-dt-bundle.js'; // eslint-disable-line
|
|
28
|
+
eval(fs.readFileSync(LH_ROOT + '/dist/lighthouse-dt-bundle.js', 'utf-8'));
|
|
27
29
|
|
|
28
30
|
global.require = originalRequire;
|
|
29
31
|
|
|
@@ -10,6 +10,7 @@ const LanternMetric = require('./lantern-metric.js');
|
|
|
10
10
|
const BaseNode = require('../../lib/dependency-graph/base-node.js');
|
|
11
11
|
const LanternFirstContentfulPaint = require('./lantern-first-contentful-paint.js');
|
|
12
12
|
const LanternInteractive = require('./lantern-interactive.js');
|
|
13
|
+
const {BLOCKING_TIME_THRESHOLD, calculateSumOfBlockingTime} = require('./tbt-utils.js');
|
|
13
14
|
|
|
14
15
|
/** @typedef {BaseNode.Node} Node */
|
|
15
16
|
|
|
@@ -66,9 +67,7 @@ class LanternTotalBlockingTime extends LanternMetric {
|
|
|
66
67
|
? extras.interactiveResult.optimisticEstimate.timeInMs
|
|
67
68
|
: extras.interactiveResult.pessimisticEstimate.timeInMs;
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
const TotalBlockingTime = require('./total-blocking-time.js');
|
|
71
|
-
const minDurationMs = TotalBlockingTime.BLOCKING_TIME_THRESHOLD;
|
|
70
|
+
const minDurationMs = BLOCKING_TIME_THRESHOLD;
|
|
72
71
|
|
|
73
72
|
const events = LanternTotalBlockingTime.getTopLevelEvents(
|
|
74
73
|
simulation.nodeTimings,
|
|
@@ -76,7 +75,7 @@ class LanternTotalBlockingTime extends LanternMetric {
|
|
|
76
75
|
);
|
|
77
76
|
|
|
78
77
|
return {
|
|
79
|
-
timeInMs:
|
|
78
|
+
timeInMs: calculateSumOfBlockingTime(
|
|
80
79
|
events,
|
|
81
80
|
fcpTimeInMs,
|
|
82
81
|
interactiveTimeMs
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
4
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const BLOCKING_TIME_THRESHOLD = 50;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {Array<{start: number, end: number, duration: number}>} topLevelEvents
|
|
12
|
+
* @param {number} startTimeMs
|
|
13
|
+
* @param {number} endTimeMs
|
|
14
|
+
* @return {number}
|
|
15
|
+
*/
|
|
16
|
+
function calculateSumOfBlockingTime(topLevelEvents, startTimeMs, endTimeMs) {
|
|
17
|
+
if (endTimeMs <= startTimeMs) return 0;
|
|
18
|
+
|
|
19
|
+
const threshold = BLOCKING_TIME_THRESHOLD;
|
|
20
|
+
let sumBlockingTime = 0;
|
|
21
|
+
for (const event of topLevelEvents) {
|
|
22
|
+
// Early exit for small tasks, which should far outnumber long tasks.
|
|
23
|
+
if (event.duration < threshold) continue;
|
|
24
|
+
|
|
25
|
+
// We only want to consider tasks that fall in our time range (FCP and TTI for navigations).
|
|
26
|
+
// FCP is picked as the lower bound because there is little risk of user input happening
|
|
27
|
+
// before FCP so Long Queuing Qelay regions do not harm user experience. Developers should be
|
|
28
|
+
// optimizing to reach FCP as fast as possible without having to worry about task lengths.
|
|
29
|
+
if (event.end < startTimeMs) continue;
|
|
30
|
+
|
|
31
|
+
// TTI is picked as the upper bound because we want a well defined end point for page load.
|
|
32
|
+
if (event.start > endTimeMs) continue;
|
|
33
|
+
|
|
34
|
+
// We first perform the clipping, and then calculate Blocking Region. So if we have a 150ms
|
|
35
|
+
// task [0, 150] and FCP happens midway at 50ms, we first clip the task to [50, 150], and then
|
|
36
|
+
// calculate the Blocking Region to be [100, 150]. The rational here is that tasks before FCP
|
|
37
|
+
// are unimportant, so we care whether the main thread is busy more than 50ms at a time only
|
|
38
|
+
// after FCP.
|
|
39
|
+
const clippedStart = Math.max(event.start, startTimeMs);
|
|
40
|
+
const clippedEnd = Math.min(event.end, endTimeMs);
|
|
41
|
+
const clippedDuration = clippedEnd - clippedStart;
|
|
42
|
+
if (clippedDuration < threshold) continue;
|
|
43
|
+
|
|
44
|
+
// The duration of the task beyond 50ms at the beginning is considered the Blocking Region.
|
|
45
|
+
// Example:
|
|
46
|
+
// [ 250ms Task ]
|
|
47
|
+
// | First 50ms | Blocking Region (200ms) |
|
|
48
|
+
sumBlockingTime += clippedDuration - threshold;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return sumBlockingTime;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
BLOCKING_TIME_THRESHOLD,
|
|
56
|
+
calculateSumOfBlockingTime,
|
|
57
|
+
};
|
|
@@ -10,6 +10,7 @@ const ComputedMetric = require('./metric.js');
|
|
|
10
10
|
const TraceProcessor = require('../../lib/tracehouse/trace-processor.js');
|
|
11
11
|
const LanternTotalBlockingTime = require('./lantern-total-blocking-time.js');
|
|
12
12
|
const TimetoInteractive = require('./interactive.js');
|
|
13
|
+
const {calculateSumOfBlockingTime} = require('./tbt-utils.js');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @fileoverview This audit determines Total Blocking Time.
|
|
@@ -25,57 +26,6 @@ const TimetoInteractive = require('./interactive.js');
|
|
|
25
26
|
* to smaller improvements to main thread responsiveness.
|
|
26
27
|
*/
|
|
27
28
|
class TotalBlockingTime extends ComputedMetric {
|
|
28
|
-
/**
|
|
29
|
-
* @return {number}
|
|
30
|
-
*/
|
|
31
|
-
static get BLOCKING_TIME_THRESHOLD() {
|
|
32
|
-
return 50;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @param {Array<{start: number, end: number, duration: number}>} topLevelEvents
|
|
37
|
-
* @param {number} startTimeMs
|
|
38
|
-
* @param {number} endTimeMs
|
|
39
|
-
* @return {number}
|
|
40
|
-
*/
|
|
41
|
-
static calculateSumOfBlockingTime(topLevelEvents, startTimeMs, endTimeMs) {
|
|
42
|
-
if (endTimeMs <= startTimeMs) return 0;
|
|
43
|
-
|
|
44
|
-
const threshold = TotalBlockingTime.BLOCKING_TIME_THRESHOLD;
|
|
45
|
-
let sumBlockingTime = 0;
|
|
46
|
-
for (const event of topLevelEvents) {
|
|
47
|
-
// Early exit for small tasks, which should far outnumber long tasks.
|
|
48
|
-
if (event.duration < threshold) continue;
|
|
49
|
-
|
|
50
|
-
// We only want to consider tasks that fall in our time range (FCP and TTI for navigations).
|
|
51
|
-
// FCP is picked as the lower bound because there is little risk of user input happening
|
|
52
|
-
// before FCP so Long Queuing Qelay regions do not harm user experience. Developers should be
|
|
53
|
-
// optimizing to reach FCP as fast as possible without having to worry about task lengths.
|
|
54
|
-
if (event.end < startTimeMs) continue;
|
|
55
|
-
|
|
56
|
-
// TTI is picked as the upper bound because we want a well defined end point for page load.
|
|
57
|
-
if (event.start > endTimeMs) continue;
|
|
58
|
-
|
|
59
|
-
// We first perform the clipping, and then calculate Blocking Region. So if we have a 150ms
|
|
60
|
-
// task [0, 150] and FCP happens midway at 50ms, we first clip the task to [50, 150], and then
|
|
61
|
-
// calculate the Blocking Region to be [100, 150]. The rational here is that tasks before FCP
|
|
62
|
-
// are unimportant, so we care whether the main thread is busy more than 50ms at a time only
|
|
63
|
-
// after FCP.
|
|
64
|
-
const clippedStart = Math.max(event.start, startTimeMs);
|
|
65
|
-
const clippedEnd = Math.min(event.end, endTimeMs);
|
|
66
|
-
const clippedDuration = clippedEnd - clippedStart;
|
|
67
|
-
if (clippedDuration < threshold) continue;
|
|
68
|
-
|
|
69
|
-
// The duration of the task beyond 50ms at the beginning is considered the Blocking Region.
|
|
70
|
-
// Example:
|
|
71
|
-
// [ 250ms Task ]
|
|
72
|
-
// | First 50ms | Blocking Region (200ms) |
|
|
73
|
-
sumBlockingTime += clippedDuration - threshold;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return sumBlockingTime;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
29
|
/**
|
|
80
30
|
* @param {LH.Artifacts.MetricComputationData} data
|
|
81
31
|
* @param {LH.Artifacts.ComputedContext} context
|
|
@@ -100,7 +50,7 @@ class TotalBlockingTime extends ComputedMetric {
|
|
|
100
50
|
const interactiveTimeMs = (await TimetoInteractive.request(metricData, context)).timing;
|
|
101
51
|
|
|
102
52
|
return {
|
|
103
|
-
timing:
|
|
53
|
+
timing: calculateSumOfBlockingTime(
|
|
104
54
|
events,
|
|
105
55
|
firstContentfulPaint,
|
|
106
56
|
interactiveTimeMs
|
|
@@ -108,7 +58,7 @@ class TotalBlockingTime extends ComputedMetric {
|
|
|
108
58
|
};
|
|
109
59
|
} else {
|
|
110
60
|
return {
|
|
111
|
-
timing:
|
|
61
|
+
timing: calculateSumOfBlockingTime(
|
|
112
62
|
events,
|
|
113
63
|
0,
|
|
114
64
|
data.processedTrace.timestamps.traceEnd
|
|
@@ -10,7 +10,7 @@ const NetworkRecords = require('./network-records.js');
|
|
|
10
10
|
const URL = require('../lib/url-shim.js');
|
|
11
11
|
const NetworkRequest = require('../lib/network-request.js');
|
|
12
12
|
const Budget = require('../config/budget.js');
|
|
13
|
-
const Util = require('../util-commonjs.js');
|
|
13
|
+
const {Util} = require('../util-commonjs.js');
|
|
14
14
|
|
|
15
15
|
/** @typedef {{count: number, resourceSize: number, transferSize: number}} ResourceEntry */
|
|
16
16
|
|
|
@@ -203,6 +203,18 @@ function expandAuditShorthand(audit) {
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
/** @type {Map<string, any>} */
|
|
207
|
+
const bundledModules = new Map(/* BUILD_REPLACE_BUNDLED_MODULES */);
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Wraps `require` with an entrypoint for bundled dynamic modules.
|
|
211
|
+
* See build-bundle.js
|
|
212
|
+
* @param {string} requirePath
|
|
213
|
+
*/
|
|
214
|
+
function requireWrapper(requirePath) {
|
|
215
|
+
return bundledModules.get(requirePath) || require(requirePath);
|
|
216
|
+
}
|
|
217
|
+
|
|
206
218
|
/**
|
|
207
219
|
* @param {string} gathererPath
|
|
208
220
|
* @param {Array<string>} coreGathererList
|
|
@@ -218,7 +230,7 @@ function requireGatherer(gathererPath, coreGathererList, configDir) {
|
|
|
218
230
|
requirePath = resolveModulePath(gathererPath, configDir, 'gatherer');
|
|
219
231
|
}
|
|
220
232
|
|
|
221
|
-
const GathererClass = /** @type {GathererConstructor} */ (
|
|
233
|
+
const GathererClass = /** @type {GathererConstructor} */ (requireWrapper(requirePath));
|
|
222
234
|
|
|
223
235
|
return {
|
|
224
236
|
instance: new GathererClass(),
|
|
@@ -228,14 +240,13 @@ function requireGatherer(gathererPath, coreGathererList, configDir) {
|
|
|
228
240
|
}
|
|
229
241
|
|
|
230
242
|
/**
|
|
231
|
-
*
|
|
232
243
|
* @param {string} auditPath
|
|
233
244
|
* @param {Array<string>} coreAuditList
|
|
234
245
|
* @param {string=} configDir
|
|
235
246
|
* @return {LH.Config.AuditDefn['implementation']}
|
|
236
247
|
*/
|
|
237
248
|
function requireAudit(auditPath, coreAuditList, configDir) {
|
|
238
|
-
// See if the audit is a Lighthouse core audit.
|
|
249
|
+
// See if the audit is a Lighthouse core audit.
|
|
239
250
|
const auditPathJs = `${auditPath}.js`;
|
|
240
251
|
const coreAudit = coreAuditList.find(a => a === auditPathJs);
|
|
241
252
|
let requirePath = `../audits/${auditPath}`;
|
|
@@ -244,14 +255,14 @@ function requireAudit(auditPath, coreAuditList, configDir) {
|
|
|
244
255
|
// This is for pubads bundling.
|
|
245
256
|
requirePath = auditPath;
|
|
246
257
|
} else {
|
|
247
|
-
|
|
258
|
+
// Otherwise, attempt to find it elsewhere. This throws if not found.
|
|
248
259
|
const absolutePath = resolveModulePath(auditPath, configDir, 'audit');
|
|
249
260
|
// Use a relative path so bundler can easily expose it.
|
|
250
261
|
requirePath = path.relative(__dirname, absolutePath);
|
|
251
262
|
}
|
|
252
263
|
}
|
|
253
264
|
|
|
254
|
-
return
|
|
265
|
+
return requireWrapper(requirePath);
|
|
255
266
|
}
|
|
256
267
|
|
|
257
268
|
/**
|
|
@@ -313,7 +324,6 @@ function resolveSettings(settingsJson = {}, overrides = undefined) {
|
|
|
313
324
|
return settingsWithFlags;
|
|
314
325
|
}
|
|
315
326
|
|
|
316
|
-
|
|
317
327
|
/**
|
|
318
328
|
* @param {LH.Config.Json} configJSON
|
|
319
329
|
* @param {string | undefined} configDir
|
|
@@ -332,7 +342,7 @@ function mergePlugins(configJSON, configDir, flags) {
|
|
|
332
342
|
const pluginPath = isBundledEnvironment() ?
|
|
333
343
|
pluginName :
|
|
334
344
|
resolveModulePath(pluginName, configDir, 'plugin');
|
|
335
|
-
const rawPluginJson =
|
|
345
|
+
const rawPluginJson = requireWrapper(pluginPath);
|
|
336
346
|
const pluginJson = ConfigPlugin.parsePlugin(rawPluginJson, pluginName);
|
|
337
347
|
|
|
338
348
|
configJSON = mergeConfigFragment(configJSON, pluginJson);
|
|
@@ -569,12 +579,12 @@ function deepCloneConfigJson(json) {
|
|
|
569
579
|
module.exports = {
|
|
570
580
|
deepClone,
|
|
571
581
|
deepCloneConfigJson,
|
|
572
|
-
mergeOptionsOfItems,
|
|
573
582
|
mergeConfigFragment,
|
|
574
583
|
mergeConfigFragmentArrayByKey,
|
|
584
|
+
mergeOptionsOfItems,
|
|
575
585
|
mergePlugins,
|
|
576
|
-
resolveSettings,
|
|
577
|
-
resolveGathererToDefn,
|
|
578
586
|
resolveAuditsToDefns,
|
|
587
|
+
resolveGathererToDefn,
|
|
579
588
|
resolveModulePath,
|
|
589
|
+
resolveSettings,
|
|
580
590
|
};
|