Skip to content

Commit 48ae446

Browse files
authored
Merge pull request #10 from Webperf-se/pug
Added plugin tab in sitespeed.io HTML results
2 parents a1f72b2 + c910d0b commit 48ae446

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

lib/index.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { SitespeedioPlugin } from '@sitespeed.io/plugin';
22
import { HarAnalyzer } from './harAnalyzer.js';
3+
import path from 'node:path';
4+
import { fileURLToPath } from 'node:url';
5+
import fs from 'node:fs';
6+
const fsp = fs.promises;
37

48
// https://www.sitespeed.io/documentation/sitespeed.io/plugins/#create-your-own-plugin
59
// node bin\sitespeed.js -b edge -n 1 --plugins.add analysisstorer --plugins.add ../../../plugin-javascript/lib/index.js --browsertime.chrome.includeResponseBodies all https://webperf.se
@@ -11,17 +15,41 @@ export default class JavascriptPlugin extends SitespeedioPlugin {
1115
super({ name: pluginname, options, context, queue });
1216
}
1317

14-
open(context, options) {
18+
async open(context, options) {
1519
this.make = context.messageMaker(pluginname).make;
1620
this.harAnalyzer = new HarAnalyzer();
21+
const libFolder = fileURLToPath(new URL('..', import.meta.url));
22+
this.pluginFolder = path.resolve(libFolder);
23+
24+
this.pug = await fsp.readFile(
25+
path.resolve(this.pluginFolder, 'pug', 'index.pug'),
26+
'utf8'
27+
);
1728
}
1829

1930
async processMessage(message, queue) {
2031
// const filterRegistry = this.filterRegistry;
2132
switch (message.type) {
2233
case 'sitespeedio.setup': {
2334
// Let other plugins know that the pagenotfound plugin is alive
24-
super.sendMessage('browsertime.setup');
35+
// queue.postMessage(this.make(pluginname + '.setup'));
36+
// Add the HTML pugs
37+
queue.postMessage(
38+
this.make('html.pug', {
39+
id: pluginname,
40+
name: 'Javascript',
41+
pug: this.pug,
42+
type: 'pageSummary'
43+
})
44+
);
45+
queue.postMessage(
46+
this.make('html.pug', {
47+
id: pluginname,
48+
name: 'Javascript',
49+
pug: this.pug,
50+
type: 'run'
51+
})
52+
);
2553
break;
2654
}
2755
case 'browsertime.har': {

pug/index.pug

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
- let pluginData = pageInfo.data['webperf-plugin-javascript'].run ? pageInfo.data['webperf-plugin-javascript'].run : pageInfo.data['webperf-plugin-javascript'].pageSummary
3+
4+
h1 Issues
5+
if pluginData.knowledgeData && pluginData.knowledgeData.issues && pluginData.knowledgeData.issues.length > 0
6+
table
7+
thead
8+
tr
9+
th URL
10+
th Rule
11+
th Category
12+
th Severity
13+
th Text
14+
th Line
15+
th Column
16+
tbody
17+
each issue in pluginData.knowledgeData.issues
18+
tr
19+
td= issue.url
20+
td= issue.rule
21+
td= issue.category
22+
td= issue.severity
23+
td= issue.text
24+
td= issue.line
25+
td= issue.column
26+
else
27+
p No issues found.
28+
29+
h2 Debug: Plugin Data
30+
pre
31+
code= JSON.stringify(pluginData, null, 3)

0 commit comments

Comments
 (0)