diff --git a/lighthouse-core/report/v2/renderer/details-renderer.js b/lighthouse-core/report/v2/renderer/details-renderer.js index 295809ea14ee..57ee9507871c 100644 --- a/lighthouse-core/report/v2/renderer/details-renderer.js +++ b/lighthouse-core/report/v2/renderer/details-renderer.js @@ -15,6 +15,8 @@ */ 'use strict'; +/* globals self */ + class DetailsRenderer { /** * @param {!DOM} dom @@ -85,6 +87,8 @@ class DetailsRenderer { if (typeof module !== 'undefined' && module.exports) { module.exports = DetailsRenderer; +} else if (self) { + self.DetailsRenderer = DetailsRenderer; } /** @typedef {{type: string, text: string|undefined, header: DetailsJSON|undefined, items: Array|undefined}} */ diff --git a/lighthouse-core/report/v2/renderer/dom.js b/lighthouse-core/report/v2/renderer/dom.js index 5eaed54b92e1..ff7fa310ffb8 100644 --- a/lighthouse-core/report/v2/renderer/dom.js +++ b/lighthouse-core/report/v2/renderer/dom.js @@ -15,7 +15,7 @@ */ 'use strict'; -/* globals URL */ +/* globals URL self */ class DOM { /** @@ -48,13 +48,21 @@ class DOM { * @throws {Error} */ cloneTemplate(selector) { - const template = this._document.querySelector(selector); + const template = this._retrieveTemplate(selector); if (!template) { throw new Error(`Template not found: template${selector}`); } return this._document.importNode(template.content, true); } + /** + * @param {string} selector + * @return {!DocumentFragment} The original template content + */ + _retrieveTemplate(selector) { + return this._document.querySelector(selector); + } + /** * @param {string} text * @return {!HTMLSpanElement} @@ -87,4 +95,6 @@ class DOM { if (typeof module !== 'undefined' && module.exports) { module.exports = DOM; +} else if (self) { + self.DOM = DOM; } diff --git a/lighthouse-core/report/v2/renderer/report-renderer.js b/lighthouse-core/report/v2/renderer/report-renderer.js index d3dda8b7d5fe..b5533b21fa3c 100644 --- a/lighthouse-core/report/v2/renderer/report-renderer.js +++ b/lighthouse-core/report/v2/renderer/report-renderer.js @@ -22,7 +22,7 @@ * Dummy text for ensuring report robustness: pre$`post %%LIGHTHOUSE_JSON%% */ -/* globals DOM, DetailsRenderer */ +/* globals self */ const RATINGS = { PASS: {label: 'pass', minScore: 75}, @@ -57,9 +57,10 @@ function formatNumber(number) { class ReportRenderer { /** * @param {!Document} document + * @param {!DOM} DOM + * @param {!DetailsRenderer} DetailsRenderer */ - constructor(document) { - this._dom = new DOM(document); + constructor(document, DOM, DetailsRenderer) { this._detailsRenderer = new DetailsRenderer(this._dom); } @@ -183,6 +184,8 @@ class ReportRenderer { if (typeof module !== 'undefined' && module.exports) { module.exports = ReportRenderer; +} else if (self) { + self.ReportRenderer = ReportRenderer; } /** @typedef {{id: string, weight: number, score: number, result: {description: string, displayValue: string, helpText: string, score: number|boolean, details: DetailsRenderer.DetailsJSON|undefined}}} */ diff --git a/lighthouse-core/report/v2/report-template.html b/lighthouse-core/report/v2/report-template.html index 019c68ff6090..e06c03e08d5e 100644 --- a/lighthouse-core/report/v2/report-template.html +++ b/lighthouse-core/report/v2/report-template.html @@ -30,7 +30,7 @@