forked from web-platform-tests/wpt.fyi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-file-results.js
325 lines (295 loc) · 9.58 KB
/
test-file-results.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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/**
* Copyright 2018 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 '../node_modules/@polymer/paper-toggle-button/paper-toggle-button.js';
import '../node_modules/@polymer/polymer/lib/elements/dom-if.js';
import { html, PolymerElement } from '../node_modules/@polymer/polymer/polymer-element.js';
import { LoadingState } from './loading-state.js';
import './test-file-results-table.js';
import { TestRunsUIQuery } from './test-runs-query.js';
import { TestRunsQueryLoader } from './test-runs.js';
import './wpt-colors.js';
import { timeTaken } from './utils.js';
import { WPTFlags } from './wpt-flags.js';
import { PathInfo } from './path.js';
class TestFileResults extends WPTFlags(LoadingState(PathInfo(
TestRunsQueryLoader(TestRunsUIQuery(PolymerElement))))) {
static get template() {
return html`
<style include="wpt-colors">
:host {
display: block;
font-size: 16px;
}
h1 {
font-size: 1.5em;
}
.right {
display: flex;
justify-content: flex-end;
}
.right paper-toggle-button {
padding: 8px;
}
paper-toggle-button {
--paper-toggle-button-checked-bar-color: var(--paper-blue-500);
--paper-toggle-button-checked-button-color: var(--paper-blue-700);
--paper-toggle-button-checked-ink-color: var(--paper-blue-300);
}
</style>
<div class="right">
<paper-toggle-button checked="{{isVerbose}}">
Show Details
</paper-toggle-button>
</div>
<test-file-results-table test-runs="[[testRuns]]"
diff-run="[[diffRun]]"
only-show-differences="{{onlyShowDifferences}}"
path="[[path]]"
rows="[[rows]]"
verbose="[[isVerbose]]"
is-triage-mode="[[isTriageMode]]"
metadata-map="[[metadataMap]]">
</test-file-results-table>
`;
}
static get is() {
return 'test-file-results';
}
static get properties() {
return {
diffRun: Object,
onlyShowDifferences: {
type: Boolean,
value: false,
},
structuredSearch: Object,
resultsTable: {
type: Array,
value: [],
},
isVerbose: {
type: Boolean,
value: false,
},
rows: {
type: Array,
computed: 'computeRows(resultsTable, onlyShowDifferences)'
},
subtestRowCount: {
type: Number,
value: 0,
notify: true
},
isTriageMode: Boolean,
metadataMap: Object,
};
}
async connectedCallback() {
await super.connectedCallback();
console.assert(this.path);
console.assert(this.path[0] === '/');
}
static get observers() {
return ['loadData(path, testRuns, structuredSearch)'];
}
async loadData(path, testRuns, structuredSearch) {
// Run a search query, including subtests, as well as fetching the results file.
let [searchResults, resultsTable] = await Promise.all([
this.fetchSearchResults(path, testRuns, structuredSearch),
this.fetchTestFile(path, testRuns),
]);
this.resultsTable = this.filterResultsTableBySearch(path, resultsTable, searchResults);
}
async fetchSearchResults(path, testRuns, structuredSearch) {
if (!testRuns || !testRuns.length || !this.structuredQueries || !structuredSearch) {
return;
}
// Combine the query with " and [path]".
const q = {
and: [
{pattern: path},
structuredSearch,
]
};
const url = new URL('/api/search', window.location);
url.searchParams.set('subtests', '');
if (this.diffRun) {
url.searchParams.set('diff', true);
}
const fetchOpts = {
method: 'POST',
body: JSON.stringify({
run_ids: testRuns.map(r => r.id),
query: q,
}),
};
return await this.retry(
async() => {
const r = await window.fetch(url, fetchOpts);
if (!r.ok) {
if (fetchOpts.method === 'POST' && r.status === 422) {
throw r.status;
}
throw 'Failed to fetch results data.';
}
return r.json();
},
err => err === 422,
testRuns.length + 1,
5000
);
}
async fetchTestFile(path, testRuns) {
this.resultsTable = []; // Clear any existing rows.
if (!path || !testRuns) {
return;
}
const resultsPerTestRun = await Promise.all(
testRuns.map(tr => this.loadResultFile(tr)));
// Special setup for the first two rows (status + duration).
const resultsTable = this.resultsTableHeaders(resultsPerTestRun);
// Setup test name order according to when they appear in run results.
let allNames = [];
for (const runResults of resultsPerTestRun) {
if (runResults && runResults.subtests) {
this.mergeNamesInto(runResults.subtests.map(s => s.name), allNames);
}
}
// Copy results into resultsTable.
for (const name of allNames) {
let results = [];
for (const runResults of resultsPerTestRun) {
const result = runResults && runResults.subtests &&
runResults.subtests.find(sub => sub.name === name);
results.push(result ? {
status: result.status,
message: result.message,
} : {status: null, message: null});
}
resultsTable.push({
name,
results,
});
}
// Set name for test-level status entry after subtests discovered.
// Parameter is number of subtests.
resultsTable[0].name = this.statusName(resultsTable.length - 2);
return resultsTable;
}
async loadResultFile(testRun) {
const url = this.resultsURL(testRun, this.path);
const response = await window.fetch(url);
if (!response.ok) {
return null;
}
return response.json();
}
resultsTableHeaders(resultsPerTestRun) {
return [
{
// resultsTable[0].name will be set later depending on the number of subtests.
name: '',
results: resultsPerTestRun.map(data => {
const result = {
status: data && data.status,
message: data && data.message,
};
if (data && data.screenshots) {
result.screenshots = this.shuffleScreenshots(this.path, data.screenshots);
}
return result;
})
},
{
name: 'Duration',
results: resultsPerTestRun.map(data => ({status: data && timeTaken(data.duration), message: null}))
}
];
}
filterResultsTableBySearch(path, resultsTable, searchResults) {
if (!resultsTable || !searchResults) {
return resultsTable;
}
const test = searchResults.results.find(r => r.test === path);
if (!test) {
return resultsTable;
}
const subtests = new Set(test.subtests);
const [status, duration, ...others] = resultsTable;
const matches = others.filter(t => subtests.has(t.name));
return [status, duration, ...matches];
}
mergeNamesInto(names, allNames) {
if (!allNames.length) {
allNames.splice(0, 0, ...names);
return;
}
let lastOffset = 0;
let lastMatch = 0;
names.forEach((name, i) => {
// Optimization for "next item matches too".
let offset;
if (i === lastMatch + 1 && allNames[lastOffset + 1] === name) {
offset = lastOffset + 1;
} else {
offset = allNames.findIndex(n => n === name);
}
if (offset >= 0) {
lastOffset = offset;
lastMatch = i;
} else {
allNames.splice(lastOffset + i - lastMatch, 0, name);
}
});
}
// Slice summary file URL to infer the URL path to get single test data.
resultsURL(testRun, path) {
path = this.encodeTestPath(path);
// This is relying on the assumption that result
// files end with '-summary.json.gz' or '-summary_v2.json.gz'.
let resultsSuffix = '-summary.json.gz';
if (!testRun.results_url.includes(resultsSuffix)) {
resultsSuffix = '-summary_v2.json.gz';
}
const resultsBase = testRun.results_url.slice(0, testRun.results_url.lastIndexOf(resultsSuffix));
return `${resultsBase}${path}`;
}
statusName(numSubtests) {
return numSubtests > 0 ? 'Harness status' : 'Test status';
}
shuffleScreenshots(path, rawScreenshots) {
// Clone the data because we might modify it.
const screenshots = Object.assign({}, rawScreenshots);
// Make sure the test itself appears first in the Map to follow the
// convention of reftest-analyzer (actual, expected).
const firstScreenshot = [];
if (path in screenshots) {
firstScreenshot.push([path, screenshots[path]]);
delete screenshots[path];
}
return new Map([...firstScreenshot, ...Object.entries(screenshots)]);
}
computeRows(resultsTable, onlyShowDifferences) {
let rows = resultsTable;
if (resultsTable && resultsTable.length && onlyShowDifferences) {
const [first, ...others] = resultsTable;
rows = [first, ...others.filter(r => {
return r.results[0].status !== r.results[1].status;
})];
}
// If displaying subtests of a single test, the first two rows will
// reflect TestHarness status and duration, so we don't count them
// when displaying the number of subtests in the blue banner.
if (rows.length > 2 && rows[1].name === 'Duration') {
this.subtestRowCount = rows.length - 2;
} else {
this.subtestRowCount = 0;
}
return rows;
}
}
window.customElements.define(TestFileResults.is, TestFileResults);
export { TestFileResults };