lighthouse 8.6.0-dev.20211102 → 8.6.0-dev.20211106
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 +8 -8
- package/dist/report/standalone.js +40 -34
- package/flow-report/assets/standalone-flow-template.html +3 -2
- package/flow-report/src/icons.tsx +9 -0
- package/flow-report/src/sidebar/sidebar.tsx +18 -5
- package/flow-report/src/wrappers/report-renderer.tsx +1 -0
- package/flow-report/src/wrappers/report.tsx +2 -3
- package/flow-report/standalone-flow.tsx +4 -3
- package/flow-report/test/sidebar/sidebar-test.tsx +43 -1
- package/package.json +1 -1
- package/report/assets/standalone-template.html +2 -3
- package/report/assets/styles.css +1 -1
- package/report/clients/bundle.js +1 -0
- package/report/clients/standalone.js +6 -13
- package/report/renderer/api.js +32 -0
- package/report/renderer/category-renderer.js +1 -1
- package/report/renderer/components.js +26 -26
- package/report/renderer/dom.js +16 -1
- package/report/renderer/drop-down-menu.js +2 -2
- package/report/renderer/element-screenshot-renderer.js +6 -6
- package/report/renderer/features-util.js +1 -1
- package/report/renderer/report-renderer.js +32 -9
- package/report/renderer/report-ui-features.js +34 -30
- package/report/renderer/swap-locale-feature.js +3 -3
- package/report/renderer/topbar-features.js +52 -48
- package/report/test/clients/bundle-test.js +8 -0
- package/report/test/renderer/report-renderer-axe-test.js +5 -2
- package/report/test/renderer/report-renderer-test.js +13 -10
- package/report/test/renderer/report-ui-features-test.js +10 -1
- package/report/test-assets/faux-psi-template.html +2 -7
- package/report/test-assets/faux-psi.js +15 -34
- package/report/types/html-renderer.d.ts +2 -0
- package/report/types/report-renderer.d.ts +23 -0
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import {strict as assert} from 'assert';
|
|
11
11
|
|
|
12
12
|
import jsdom from 'jsdom';
|
|
13
|
+
import {jest} from '@jest/globals';
|
|
13
14
|
|
|
14
15
|
import {Util} from '../../renderer/util.js';
|
|
15
16
|
import URL from '../../../lighthouse-core/lib/url-shim.js';
|
|
@@ -26,6 +27,8 @@ describe('ReportRenderer', () => {
|
|
|
26
27
|
let sampleResults;
|
|
27
28
|
|
|
28
29
|
beforeAll(() => {
|
|
30
|
+
global.console.warn = jest.fn();
|
|
31
|
+
|
|
29
32
|
// Stub out matchMedia for Node.
|
|
30
33
|
global.matchMedia = function() {
|
|
31
34
|
return {
|
|
@@ -50,7 +53,7 @@ describe('ReportRenderer', () => {
|
|
|
50
53
|
|
|
51
54
|
describe('renderReport', () => {
|
|
52
55
|
it('should render a report', () => {
|
|
53
|
-
const container = renderer._dom.
|
|
56
|
+
const container = renderer._dom.document().body;
|
|
54
57
|
const output = renderer.renderReport(sampleResults, container);
|
|
55
58
|
assert.ok(output.querySelector('.lh-header-container'), 'has a header');
|
|
56
59
|
assert.ok(output.querySelector('.lh-report'), 'has report body');
|
|
@@ -60,7 +63,7 @@ describe('ReportRenderer', () => {
|
|
|
60
63
|
});
|
|
61
64
|
|
|
62
65
|
it('renders additional reports by replacing the existing one', () => {
|
|
63
|
-
const container = renderer._dom.
|
|
66
|
+
const container = renderer._dom.document().body;
|
|
64
67
|
const oldReport = Array.from(renderer.renderReport(sampleResults, container).children);
|
|
65
68
|
const newReport = Array.from(renderer.renderReport(sampleResults, container).children);
|
|
66
69
|
assert.ok(!oldReport.find(node => container.contains(node)), 'old report was removed');
|
|
@@ -86,7 +89,7 @@ describe('ReportRenderer', () => {
|
|
|
86
89
|
auditRefs: [],
|
|
87
90
|
};
|
|
88
91
|
|
|
89
|
-
const container = renderer._dom.
|
|
92
|
+
const container = renderer._dom.document().body;
|
|
90
93
|
const output = renderer.renderReport(sampleResultsCopy, container);
|
|
91
94
|
|
|
92
95
|
function isPWAGauge(el) {
|
|
@@ -126,7 +129,7 @@ describe('ReportRenderer', () => {
|
|
|
126
129
|
title: 'Some Plugin',
|
|
127
130
|
auditRefs: [],
|
|
128
131
|
};
|
|
129
|
-
const container = renderer._dom.
|
|
132
|
+
const container = renderer._dom.document().body;
|
|
130
133
|
const output = renderer.renderReport(sampleResultsCopy, container);
|
|
131
134
|
const scoresHeaderElem = output.querySelector('.lh-scores-header');
|
|
132
135
|
|
|
@@ -140,7 +143,7 @@ describe('ReportRenderer', () => {
|
|
|
140
143
|
});
|
|
141
144
|
|
|
142
145
|
it('should not mutate a report object', () => {
|
|
143
|
-
const container = renderer._dom.
|
|
146
|
+
const container = renderer._dom.document().body;
|
|
144
147
|
const originalResults = JSON.parse(JSON.stringify(sampleResults));
|
|
145
148
|
renderer.renderReport(sampleResults, container);
|
|
146
149
|
assert.deepStrictEqual(sampleResults, originalResults);
|
|
@@ -148,13 +151,13 @@ describe('ReportRenderer', () => {
|
|
|
148
151
|
|
|
149
152
|
it('renders no warning section when no lighthouseRunWarnings occur', () => {
|
|
150
153
|
const warningResults = Object.assign({}, sampleResults, {runWarnings: []});
|
|
151
|
-
const container = renderer._dom.
|
|
154
|
+
const container = renderer._dom.document().body;
|
|
152
155
|
const output = renderer.renderReport(warningResults, container);
|
|
153
156
|
assert.strictEqual(output.querySelector('.lh-warnings--toplevel'), null);
|
|
154
157
|
});
|
|
155
158
|
|
|
156
159
|
it('renders a warning section', () => {
|
|
157
|
-
const container = renderer._dom.
|
|
160
|
+
const container = renderer._dom.document().body;
|
|
158
161
|
const output = renderer.renderReport(sampleResults, container);
|
|
159
162
|
|
|
160
163
|
const warningEls = output.querySelectorAll('.lh-warnings--toplevel > ul > li');
|
|
@@ -165,7 +168,7 @@ describe('ReportRenderer', () => {
|
|
|
165
168
|
const warningResults = Object.assign({}, sampleResults, {
|
|
166
169
|
runWarnings: ['[I am a link](https://example.com/)'],
|
|
167
170
|
});
|
|
168
|
-
const container = renderer._dom.
|
|
171
|
+
const container = renderer._dom.document().body;
|
|
169
172
|
const output = renderer.renderReport(warningResults, container);
|
|
170
173
|
|
|
171
174
|
const warningEls = output.querySelectorAll('.lh-warnings--toplevel ul li a');
|
|
@@ -196,7 +199,7 @@ describe('ReportRenderer', () => {
|
|
|
196
199
|
// Make sure we have a channel in the LHR.
|
|
197
200
|
assert.ok(lhrChannel.length > 2);
|
|
198
201
|
|
|
199
|
-
const container = renderer._dom.
|
|
202
|
+
const container = renderer._dom.document().body;
|
|
200
203
|
const output = renderer.renderReport(sampleResults, container);
|
|
201
204
|
|
|
202
205
|
const DOCS_ORIGINS = ['https://developers.google.com', 'https://web.dev'];
|
|
@@ -225,7 +228,7 @@ describe('ReportRenderer', () => {
|
|
|
225
228
|
|
|
226
229
|
assert.ok(notApplicableCount > 20); // Make sure something's being tested.
|
|
227
230
|
|
|
228
|
-
const container = renderer._dom.
|
|
231
|
+
const container = renderer._dom.document().body;
|
|
229
232
|
const reportElement = renderer.renderReport(sampleResults, container);
|
|
230
233
|
const notApplicableElementCount = reportElement
|
|
231
234
|
.querySelectorAll('.lh-audit--notapplicable').length;
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import {strict as assert} from 'assert';
|
|
11
11
|
|
|
12
12
|
import jsdom from 'jsdom';
|
|
13
|
+
import {jest} from '@jest/globals';
|
|
13
14
|
|
|
14
15
|
import reportAssets from '../../generator/report-assets.js';
|
|
15
16
|
import {Util} from '../../renderer/util.js';
|
|
@@ -33,13 +34,15 @@ describe('ReportUIFeatures', () => {
|
|
|
33
34
|
const categoryRenderer = new CategoryRenderer(dom, detailsRenderer);
|
|
34
35
|
const renderer = new ReportRenderer(dom, categoryRenderer);
|
|
35
36
|
const reportUIFeatures = new ReportUIFeatures(dom);
|
|
36
|
-
const container = dom.find('
|
|
37
|
+
const container = dom.find('body', dom.document());
|
|
37
38
|
renderer.renderReport(lhr, container);
|
|
38
39
|
reportUIFeatures.initFeatures(lhr);
|
|
39
40
|
return container;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
beforeAll(() => {
|
|
44
|
+
global.console.warn = jest.fn();
|
|
45
|
+
|
|
43
46
|
// Stub out matchMedia for Node.
|
|
44
47
|
global.matchMedia = function() {
|
|
45
48
|
return {
|
|
@@ -57,14 +60,20 @@ describe('ReportUIFeatures', () => {
|
|
|
57
60
|
|
|
58
61
|
global.HTMLElement = document.window.HTMLElement;
|
|
59
62
|
global.HTMLInputElement = document.window.HTMLInputElement;
|
|
63
|
+
global.HTMLInputElement = document.window.HTMLInputElement;
|
|
60
64
|
|
|
61
65
|
global.window = document.window;
|
|
66
|
+
global.window.requestAnimationFrame = fn => fn();
|
|
62
67
|
global.window.getComputedStyle = function() {
|
|
63
68
|
return {
|
|
64
69
|
marginTop: '10px',
|
|
65
70
|
height: '10px',
|
|
66
71
|
};
|
|
67
72
|
};
|
|
73
|
+
global.window.ResizeObserver = class ResizeObserver {
|
|
74
|
+
observe() { }
|
|
75
|
+
unobserve() { }
|
|
76
|
+
};
|
|
68
77
|
|
|
69
78
|
dom = new DOM(document.window.document);
|
|
70
79
|
sampleResults = Util.prepareReportResult(sampleResultsOrig);
|
|
@@ -66,7 +66,6 @@
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
.tab-panel {
|
|
69
|
-
padding: 30px 0;
|
|
70
69
|
border-top: 1px solid #ccc;
|
|
71
70
|
}
|
|
72
71
|
|
|
@@ -101,13 +100,9 @@ body {
|
|
|
101
100
|
<label for="tab2">Desktop</label>
|
|
102
101
|
|
|
103
102
|
<div class="tab-panels">
|
|
104
|
-
<section id="mobile" class="tab-panel">
|
|
105
|
-
<main></main>
|
|
106
|
-
</section>
|
|
103
|
+
<section id="mobile" class="tab-panel"></section>
|
|
107
104
|
|
|
108
|
-
<section id="desktop" class="tab-panel">
|
|
109
|
-
<main></main>
|
|
110
|
-
</section>
|
|
105
|
+
<section id="desktop" class="tab-panel"></section>
|
|
111
106
|
|
|
112
107
|
</div>
|
|
113
108
|
</div>
|
|
@@ -26,43 +26,25 @@ const lighthouseRenderer = window['report'];
|
|
|
26
26
|
for (const [tabId, lhr] of Object.entries(lhrs)) {
|
|
27
27
|
await distinguishLHR(lhr, tabId);
|
|
28
28
|
|
|
29
|
-
const container = document.querySelector(
|
|
29
|
+
const container = document.querySelector(`section#${tabId}`);
|
|
30
30
|
if (!container) throw new Error('Unexpected DOM. Bailing.');
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const dom = new lighthouseRenderer.DOM(doc);
|
|
46
|
-
return new lighthouseRenderer.ReportRenderer(dom);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const renderer = getRenderer(reportContainer.ownerDocument);
|
|
50
|
-
reportContainer.classList.add('lh-root', 'lh-vars');
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
renderer.renderReport(lhrData, reportContainer);
|
|
54
|
-
// TODO: handle topbar removal better
|
|
55
|
-
// TODO: display warnings if appropriate.
|
|
56
|
-
for (const el of reportContainer.querySelectorAll('.lh-topbar, .lh-warnings')) {
|
|
57
|
-
el.setAttribute('hidden', 'true');
|
|
32
|
+
try {
|
|
33
|
+
const reportRootEl = lighthouseRenderer.renderReport(lhr, {
|
|
34
|
+
omitTopbar: true,
|
|
35
|
+
disableAutoDarkModeAndFireworks: true,
|
|
36
|
+
});
|
|
37
|
+
// TODO: display warnings if appropriate.
|
|
38
|
+
for (const el of reportRootEl.querySelectorAll('.lh-warnings')) {
|
|
39
|
+
el.setAttribute('hidden', 'true');
|
|
40
|
+
}
|
|
41
|
+
container.append(reportRootEl);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
console.error(e);
|
|
44
|
+
container.textContent = 'Error: LHR failed to render.';
|
|
58
45
|
}
|
|
59
|
-
const features = new lighthouseRenderer.ReportUIFeatures(renderer._dom);
|
|
60
|
-
features.initFeatures(lhrData);
|
|
61
|
-
} catch (e) {
|
|
62
|
-
console.error(e);
|
|
63
|
-
reportContainer.textContent = 'Error: LHR failed to render.';
|
|
64
46
|
}
|
|
65
|
-
}
|
|
47
|
+
})();
|
|
66
48
|
|
|
67
49
|
|
|
68
50
|
/**
|
|
@@ -72,7 +54,6 @@ function renderLHReport(lhrData, reportContainer) {
|
|
|
72
54
|
* @param {string} tabId
|
|
73
55
|
*/
|
|
74
56
|
async function distinguishLHR(lhr, tabId) {
|
|
75
|
-
lhr.categories.performance.title += ` ${tabId}`; // for easier identification
|
|
76
57
|
if (tabId === 'desktop') {
|
|
77
58
|
lhr.categories.performance.score = 0.81;
|
|
78
59
|
}
|
|
@@ -8,6 +8,7 @@ import AuditDetails from '../../types/lhr/audit-details';
|
|
|
8
8
|
import {FormattedIcu as FormattedIcu_, IcuMessage as IcuMessage_} from '../../types/lhr/i18n';
|
|
9
9
|
import LHResult from '../../types/lhr/lhr';
|
|
10
10
|
import ReportResult_ from './report-result';
|
|
11
|
+
import Renderer_ from './report-renderer';
|
|
11
12
|
import * as Settings from '../../types/lhr/settings';
|
|
12
13
|
import Treemap_ from '../../types/lhr/treemap';
|
|
13
14
|
|
|
@@ -16,6 +17,7 @@ declare global {
|
|
|
16
17
|
module LH {
|
|
17
18
|
export import Result = LHResult;
|
|
18
19
|
export import ReportResult = ReportResult_;
|
|
20
|
+
export import Renderer = Renderer_;
|
|
19
21
|
export import Locale = Settings.Locale;
|
|
20
22
|
export type IcuMessage = IcuMessage_;
|
|
21
23
|
export type FormattedIcu<T> = FormattedIcu_<T>;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
|
|
7
|
+
import { Result as AuditResult } from "../../types/lhr/audit-result";
|
|
8
|
+
|
|
9
|
+
declare module Renderer {
|
|
10
|
+
function renderReport(lhr: AuditResult, options?: Options): HTMLElement;
|
|
11
|
+
|
|
12
|
+
interface Options {
|
|
13
|
+
/**
|
|
14
|
+
* Don't automatically apply dark-mode to dark based on (prefers-color-scheme: dark). (DevTools and PSI don't want this.)
|
|
15
|
+
* Also, the fireworks easter-egg will want to flip to dark, so this setting will also disable chance of fireworks. */
|
|
16
|
+
disableAutoDarkModeAndFireworks?: boolean;
|
|
17
|
+
|
|
18
|
+
/** Disable the topbar UI component */
|
|
19
|
+
omitTopbar?: boolean;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default Renderer;
|