Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(devtools): fix after renaming standalone-template.html #12765

Merged
merged 3 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/build-dt-report-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ writeFile('report-generator.d.ts', 'export {}');

const pathToReportAssets = require.resolve('../clients/devtools-report-assets.js');
browserify(generatorFilename, {standalone: 'Lighthouse.ReportGenerator'})
// Shims './html/html-report-assets.js' to resolve to devtools-report-assets.js
.require(pathToReportAssets, {expose: './html/html-report-assets.js'})
// Shims './report/report-assets.js' to resolve to devtools-report-assets.js
.require(pathToReportAssets, {expose: './report-assets.js'})
.bundle((err, src) => {
if (err) throw err;
fs.writeFileSync(bundleOutFile, src.toString());
Expand Down
1 change: 1 addition & 0 deletions report/assets/standalone-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

<script>window.__LIGHTHOUSE_JSON__ = %%LIGHTHOUSE_JSON%%;</script>
<script>%%LIGHTHOUSE_JAVASCRIPT%%
__initLighthouseReport__();
//# sourceURL=compiled-reportrenderer.js
</script>
<script>console.log('window.__LIGHTHOUSE_JSON__', __LIGHTHOUSE_JSON__);</script>
Expand Down
56 changes: 29 additions & 27 deletions report/clients/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

/* global document window ga DOM ReportRenderer ReportUIFeatures Logger */

(function __initLighthouseReport__() {
// Used by standalone.html
// eslint-disable-next-line no-unused-vars
function __initLighthouseReport__() {
const dom = new DOM(document);
const renderer = new ReportRenderer(dom);
const container = dom.find('main', document);
Expand All @@ -20,33 +22,33 @@
// is in the document.
const features = new ReportUIFeatures(dom);
features.initFeatures(lhr);
})();

document.addEventListener('lh-analytics', /** @param {Event} e */ e => {
// @ts-expect-error
if (window.ga) ga(e.detail.cmd, e.detail.fields);
});
document.addEventListener('lh-analytics', /** @param {Event} e */ e => {
// @ts-expect-error
if (window.ga) ga(e.detail.cmd, e.detail.fields);
});

document.addEventListener('lh-log', /** @param {Event} e */ e => {
const el = document.querySelector('#lh-log');
if (!el) return;
document.addEventListener('lh-log', /** @param {Event} e */ e => {
const el = document.querySelector('#lh-log');
if (!el) return;

const logger = new Logger(el);
// @ts-expect-error
const detail = e.detail;
const logger = new Logger(el);
// @ts-expect-error
const detail = e.detail;

switch (detail.cmd) {
case 'log':
logger.log(detail.msg);
break;
case 'warn':
logger.warn(detail.msg);
break;
case 'error':
logger.error(detail.msg);
break;
case 'hide':
logger.hide();
break;
}
});
switch (detail.cmd) {
case 'log':
logger.log(detail.msg);
break;
case 'warn':
logger.warn(detail.msg);
break;
case 'error':
logger.error(detail.msg);
break;
case 'hide':
logger.hide();
break;
}
});
}