-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.mjs
304 lines (265 loc) · 7.81 KB
/
main.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
const pf = new Intl.NumberFormat('en', {
style: 'unit',
unit: 'percent',
maximumFractionDigits: 2,
});
const searchParams = new URLSearchParams(window.location.search);
const startDate = searchParams.has('start-date')
? Date.parse(searchParams.get('start-date'))
: new Date(new Date().getFullYear(), 0, 1);
function formatPercentage(number) {
return pf.format(number * 100);
}
function formatDate(date) {
return date.toISOString().slice(0, 'yyyy-mm-dd'.length);
}
function buildTooltip(label, counts) {
return `
<div style="padding: 10px; font-size: 18px;">
<h3 style="margin: 0;">${label}</h3>
<div>Total: ${counts.total}</div>
<div>Passing: ${counts.passing} (${formatPercentage(
counts.passing / counts.total,
)})</div>
<div>Skipping: ${counts.skipping}</div>
<div>Failing: ${counts.failing}</div>
</div>
`;
}
async function createMainChart(showAllTests = false) {
const response = await fetch(
showAllTests ? './data-all.json' : './data.json',
);
const entries = await response.json();
const chartData = [];
let prev = [];
for (const entry of entries.reverse()) {
const { date, firefoxCounts, chromeCounts } = entry;
if (prev[0] === chromeCounts.passing && prev[1] === firefoxCounts.passing) {
continue;
}
prev = [chromeCounts.passing, firefoxCounts.passing];
chartData.push([
new Date(date),
(firefoxCounts.passing / firefoxCounts.total) * 100,
(chromeCounts.passing / chromeCounts.total) * 100,
buildTooltip(
'Firefox ' + new Date(date).toLocaleDateString(),
firefoxCounts,
),
buildTooltip(
'Chrome ' + new Date(date).toLocaleDateString(),
chromeCounts,
),
]);
if (new Date(date) < startDate) {
break;
}
}
chartData.reverse();
const ctx = document.getElementById('chart');
const getOrCreateTooltip = (chart) => {
let tooltipEl = chart.canvas.parentNode.querySelector('div');
if (!tooltipEl) {
tooltipEl = document.createElement('div');
tooltipEl.style.background = 'rgb(0 0 0 / 70%)';
tooltipEl.style.borderRadius = '3px';
tooltipEl.style.color = 'white';
tooltipEl.style.opacity = 1;
tooltipEl.style.pointerEvents = 'none';
tooltipEl.style.position = 'absolute';
tooltipEl.style.transform = 'translate(-50%, 0)';
tooltipEl.style.transition = 'all .1s ease';
const table = document.createElement('table');
table.style.margin = '0px';
tooltipEl.appendChild(table);
chart.canvas.parentNode.appendChild(tooltipEl);
}
return tooltipEl;
};
const externalTooltipHandler = (context) => {
// Tooltip Element
const { chart, tooltip } = context;
const tooltipEl = getOrCreateTooltip(chart);
// Hide if no tooltip
if (tooltip.opacity === 0) {
tooltipEl.style.opacity = 0;
return;
}
// Set Text
if (tooltip.body) {
const dataPoints = tooltip.dataPoints;
const dataPoint = dataPoints[0];
const dataIndex = dataPoint.dataIndex;
const datasetIndex = dataPoint.datasetIndex;
tooltipEl.innerHTML = chartData[dataIndex][3 + datasetIndex];
}
const { offsetLeft: positionX, offsetTop: positionY } = chart.canvas;
// Display, position, and set styles for font
tooltipEl.style.opacity = 1;
tooltipEl.style.left = positionX + tooltip.caretX + 'px';
tooltipEl.style.top = Math.max(positionY + tooltip.caretY - 200, 0) + 'px';
tooltipEl.style.font = tooltip.options.bodyFont.string;
tooltipEl.style.padding =
tooltip.options.padding + 'px ' + tooltip.options.padding + 'px';
};
if (window.innerWidth > 2000) {
Chart.defaults.font.size = 38;
}
new Chart(ctx, {
type: 'bar',
data: {
labels: chartData.map((item) => formatDate(item[0])),
datasets: [
{
label: '% tests passed (Firefox)',
data: chartData.map((item) => item[1]),
borderWidth: 1,
},
{
label: '% tests passed (Chrome)',
data: chartData.map((item) => item[2]),
borderWidth: 1,
},
],
},
options: {
plugins: {
tooltip: {
enabled: false,
external: externalTooltipHandler,
},
},
scales: {
y: {
beginAtZero: true,
min: 0,
max: 100,
ticks: {
callback: function (value, index, ticks) {
return value + '%';
},
},
},
},
},
});
}
async function createFirefoxDeltaChart() {
const response = await fetch('./firefox-delta-count.json');
const entries = await response.json();
const chartData = [];
for (const entry of entries.reverse()) {
if (!entry) {
continue;
}
const { date, failing, passing } = entry;
chartData.push([new Date(date), failing, passing]);
if (new Date(date) < startDate) {
break;
}
}
chartData.reverse();
const ctx = document.getElementById('chart');
if (window.innerWidth > 2000) {
Chart.defaults.font.size = 38;
}
const datasets = [
{
label: 'Tests failing with Firefox BiDi but passing with Firefox CDP',
shortLabel: 'Tests failing',
data: chartData.map((item) => item[1]),
borderWidth: 1,
},
];
if (searchParams.has('firefox-delta-all')) {
// Optionally show the new tests passing with BiDi but not with CDP
datasets.push({
label: 'Tests passing with Firefox BiDi but failing with Firefox CDP',
shortLabel: 'Tests passing',
data: chartData.map((item) => item[2]),
borderWidth: 1,
});
}
new Chart(ctx, {
type: 'line',
data: {
labels: chartData.map((item) => formatDate(item[0])),
datasets,
},
options: {
plugins: {
tooltip: {
callbacks: {
label: (context) =>
context.dataset.shortLabel + ': ' + context.parsed.y,
},
},
},
scales: {
y: {
beginAtZero: true,
min: 0,
},
},
},
});
}
async function main() {
const allTests = searchParams.has('all');
// Add ?firefox-delta to the URL to see data focused on Firefox BiDi vs
// Firefox CDP.
if (searchParams.has('firefox-delta')) {
await createFirefoxDeltaChart();
} else {
await createMainChart(allTests);
}
for (const link of document.querySelectorAll('.json-link')) {
let filename = link.dataset.name;
if (allTests) {
filename += '-all';
}
link.href = `https://puppeteer.github.io/ispuppeteerwebdriverbidiready/${filename}.json`;
}
if (allTests) {
document.querySelector('#ready').style.display = 'none';
document.querySelector('[href="#ready"]').style.display = 'none';
}
const timeEl = document.querySelector('time');
const date = formatDate(new Date());
timeEl.textContent = date;
document.querySelector('#delta').textContent = (
await fetch(allTests ? './firefox-delta-all.json' : './firefox-delta.json')
.then((res) => res.json())
.catch(() => {
return {
failing: 'X',
};
})
).failing;
const firefoxFailing = await fetch(
allTests ? './firefox-failing-all.json' : './firefox-failing.json',
)
.then((res) => res.json())
.catch(() => {
return {
failing: [],
pending: [],
};
});
document.querySelector('#firefox-failing').textContent =
firefoxFailing.failing.length + firefoxFailing.pending.length;
const chromeFailing = await fetch(
allTests ? './chrome-failing-all.json' : './chrome-failing.json',
)
.then((res) => res.json())
.catch(() => {
return {
failing: [],
pending: [],
};
});
document.querySelector('#chrome-failing').textContent =
chromeFailing.failing.length + chromeFailing.pending.length;
}
main();