-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathtest-results-history-timeline.js
277 lines (234 loc) · 8.51 KB
/
test-results-history-timeline.js
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
/**
* Copyright 2023 The WPT Dashboard Project. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
import { PolymerElement, html } from '../node_modules/@polymer/polymer/polymer-element.js';
const pageStyle = getComputedStyle(document.body);
import { PathInfo } from './path.js';
const PASS_COLOR = pageStyle.getPropertyValue('--paper-green-300');
const FAIL_COLOR = pageStyle.getPropertyValue('--paper-red-300');
const NEUTRAL_COLOR = pageStyle.getPropertyValue('--paper-grey-300');
const COLOR_MAPPING = {
// Passing statuses
OK: PASS_COLOR,
PASS: PASS_COLOR,
// Failing statuses
CRASHED: FAIL_COLOR,
ERROR: FAIL_COLOR,
FAIL: FAIL_COLOR,
NOTRUN: FAIL_COLOR,
PRECONDITION_FAILED: FAIL_COLOR,
TIMEOUT: FAIL_COLOR,
// Neutral statuses
MISSING: NEUTRAL_COLOR,
SKIPPED: NEUTRAL_COLOR,
default: NEUTRAL_COLOR,
};
const BROWSER_NAMES = [
'chrome',
'edge',
'firefox',
'safari'
];
class TestResultsTimeline extends PathInfo(PolymerElement) {
static get template() {
return html`
<style>
.chart rect, .chart text {
cursor: pointer;
}
.browser {
height: 2rem;
margin-bottom: -0.5rem;
}
</style>
<h2>
<img class="browser" alt="chrome chrome,canary,experimental,master,taskcluster,user:chromium-wpt-export-bot,prod logo" src="/static/chrome-canary_64x64.png">
Chrome
</h2>
<div class="chart" id="chromeHistoryChart"></div>
<h2>
<img class="browser" alt="edge azure,dev,edge,edgechromium,experimental,master,prod logo" src="/static/edge-dev_64x64.png">
Edge
</h2>
<div class="chart" id="edgeHistoryChart"></div>
<h2>
<img class="browser" alt="firefox experimental,firefox,master,nightly,taskcluster,user:chromium-wpt-export-bot,prod logo" src="/static/firefox-nightly_64x64.png">
Firefox
</h2>
<div class="chart" id="firefoxHistoryChart"></div>
<h2>
<img class="browser" alt="safari azure,experimental,master,preview,safari,prod logo" src="/static/safari-preview_64x64.png">
Safari
</h2>
<div class="chart" id="safariHistoryChart"></div>
`;
}
static get properties() {
return {
dataTable: Object,
runIDs: Array,
path: String,
showTestHistory: {
type: Boolean,
value: false,
},
subtestNames: Array,
};
}
static get observers() {
return [
'displayCharts(showTestHistory, path, subtestNames)',
];
}
static get is() {
return 'test-results-history-timeline';
}
displayCharts(showTestHistory, path, subtestNames) {
if (!path || !showTestHistory || !this.computePathIsATestFile(path)) {
return;
}
// Get the test history data and then populate the chart
Promise.all([
this.getTestHistory(path),
this.loadCharts()
]).then(() => this.updateAllCharts(this.historicalData, subtestNames));
// Google Charts is not responsive, even if one sets a percentage-width, so
// we add a resize observer to redraw the chart if the size changes.
window.addEventListener('resize', () => {
this.updateAllCharts(this.historicalData, subtestNames);
});
}
// Load Google charts for test history display
async loadCharts() {
await window.google.charts.load('current', { packages: ['timeline'] });
}
updateAllCharts(historicalData, subtestNames) {
const divNames = [
'chromeHistoryChart',
'edgeHistoryChart',
'firefoxHistoryChart',
'safariHistoryChart'
];
// Render charts using an array
this.charts = [null, null, null, null];
// Store run IDs for creating URLs
this.chartRunIDs = [[],[],[],[]];
divNames.forEach((name, i) => {
this.updateChart(historicalData[BROWSER_NAMES[i]], name, i, subtestNames);
});
}
updateChart(browserTestData, divID, chartIndex, subtestNames) {
// Our observer may be called before the historical data has been fetched,
// so debounce that.
if (!browserTestData || !subtestNames) {
return;
}
// Fetching the data table first ensures that Google Charts has been loaded.
// Using timeline chart
// https://developers.google.com/chart/interactive/docs/gallery/timeline
const div = this.$[divID];
this.charts[chartIndex] = new window.google.visualization.Timeline(div);
this.dataTable = new window.google.visualization.DataTable();
// Set up columns, including tooltip information and style guidelines
this.dataTable.addColumn({ type: 'string', id: 'Subtest' });
this.dataTable.addColumn({ type: 'string', id: 'Status' });
// style and tooltip columns that are not displayed
this.dataTable.addColumn({ type: 'string', id: 'style', role: 'style' });
this.dataTable.addColumn({ type: 'string', role: 'tooltip' });
this.dataTable.addColumn({ type: 'date', id: 'Start' });
this.dataTable.addColumn({ type: 'date', id: 'End' });
const dataTableRows = [];
const now = new Date();
this.chartRunIDs[chartIndex] = [];
// Create a row for each subtest
subtestNames.forEach(subtestName => {
if (!browserTestData[subtestName]) {
return;
}
for (let i = 0; i < browserTestData[subtestName].length; i++) {
const dataPoint = browserTestData[subtestName][i];
const startDate = new Date(dataPoint.date);
// Use the next entry as the end date, or use present time if this
// is the last entry
let endDate = now;
if (i + 1 !== browserTestData[subtestName].length) {
const nextDataPoint = browserTestData[subtestName][i + 1];
endDate = new Date(nextDataPoint.date);
}
// If this is the main test status, name it based on the amount of subtests
let subtestDisplayName = subtestName;
if (subtestName === '') {
subtestDisplayName = (subtestNames.length > 1) ? 'Harness status' : 'Test status';
}
const tooltip =
`${dataPoint.status} ${startDate.toLocaleDateString()}-${endDate.toLocaleDateString()}`;
const statusColor = COLOR_MAPPING[dataPoint.status] || COLOR_MAPPING.default;
// Add the run ID to array of run IDs to use for links
this.chartRunIDs[chartIndex].push(dataPoint.run_id);
dataTableRows.push([
subtestDisplayName,
dataPoint.status,
statusColor,
tooltip,
startDate,
endDate,
]);
}
});
const getChartHeight = numOfSubTests => {
const testHeight = 41;
const xAxisHeight = 50;
if(numOfSubTests <= 30) {
return (numOfSubTests * testHeight) + xAxisHeight;
}
return (20 * testHeight) + xAxisHeight;
};
let options = {
// height = # of tests * row height + x axis labels height
height: (getChartHeight(this.subtestNames.length)),
tooltip: {
isHtml: false,
},
};
this.dataTable.addRows(dataTableRows);
// handler to allow rows to be clicked and navigate to the run url
// https://stackoverflow.com/questions/40928971/how-to-customize-google-chart-with-hyperlink-in-the-label
const statusSelectHandler = (chartIndex) => {
const selection = this.charts[chartIndex].getSelection();
if (selection.length > 0) {
const index = selection[0].row;
const runIDs = this.chartRunIDs[chartIndex];
if (index !== undefined && runIDs.length > index) {
window.open(`/results/?run_id=${runIDs[index]}`, '_blank');
}
}
};
window.google.visualization.events.addListener(
this.charts[chartIndex], 'select', () => statusSelectHandler(chartIndex));
if (dataTableRows.length > 0) {
this.charts[chartIndex].draw(this.dataTable, options);
} else {
div.innerHTML = 'No browser historical data found for this test.';
}
}
// get test history and aligned run data
async getTestHistory(path) {
// If there is existing data, clear it to make sure nothing is cached
if(this.historicalData) {
this.historicalData = {};
}
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ test_name: path})
};
this.historicalData = await fetch('/api/history', options)
.then(r => r.json()).then(data => data.results);
}
}
window.customElements.define(TestResultsTimeline.is, TestResultsTimeline);
export { TestResultsTimeline };