-
Notifications
You must be signed in to change notification settings - Fork 5
/
process-wpt-results.js
241 lines (216 loc) · 6.13 KB
/
process-wpt-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
import assert from 'node:assert/strict'
function is_object (val) {
return (
typeof val === 'object' && val !== null && val !== undefined
)
}
export function merge_nonoverlap (obj1, obj2) {
function checkNoArray (obj) {
for (const [k, v] of Object.entries(obj)) {
assert(!Array.isArray(v), `Key ${k} - arrays can't be merged`)
if (is_object(v)) {
checkNoArray(v)
}
}
return obj
}
checkNoArray(obj1)
const result = obj1
for (const [k, v] of Object.entries(obj2)) {
if (is_object(v)) {
if (result[k] === undefined) {
result[k] = checkNoArray(v)
} else {
assert(is_object(result[k]), `Key ${k} is not an object`)
result[k] = merge_nonoverlap(obj1[k], v)
}
} else {
assert(!Array.isArray(v), `Key ${k} - arrays can't be merged`)
assert(!(k in obj1), `Key ${k} overlaps`)
result[k] = v
}
}
return result
}
export function process_raw_results (raw_results) {
const test_scores = {}
const run_info = raw_results.run_info
for (const test of raw_results.results) {
const test_name = test.test
const test_status = test.status
const test_score = {
score: test_status === 'PASS' ? 1 : 0,
subtests: {}
}
test_scores[test_name] = test_score
for (const subtest of test.subtests) {
test_score.subtests[subtest.name] = {
score: subtest.status === 'PASS' ? 1 : 0
}
}
}
return { run_info, test_scores }
}
export function focus_areas_map (run) {
const map = {}
for (const test of Object.keys(run.test_scores)) {
map[test] = []
for (const [area_key, area] of Object.entries(FOCUS_AREAS)) {
if (area.predicate(test)) {
map[test].push(area_key)
}
}
}
return map
}
function regex_predicate (exp) {
return test_name => exp.test(test_name)
}
function prefix_predicate (prefix) {
return test_name => test_name.startsWith(prefix)
}
const CSS2_FOCUS_FOLDERS = [
'abspos',
'box-display',
'floats',
'floats-clear',
'linebox',
'margin-padding-clear',
'normal-flow',
'positioning'
]
const CSS_TABLES_PREDICATE = /^\/css\/(CSS2\/tables|css-tables)\//
const FOCUS_AREAS = {
all: {
name: 'All WPT tests',
predicate: prefix_predicate(''),
order: 0
},
css: {
name: '/css',
predicate: prefix_predicate('/css/'),
order: 1
},
css2: {
name: '/css/CSS2',
predicate: prefix_predicate('/css/CSS2/'),
order: 2
},
csstable: {
name: '/css/CSS2/tables & /css/css-tables',
predicate: regex_predicate(CSS_TABLES_PREDICATE),
order: 90
},
cssom: {
name: '/css/cssom',
predicate: prefix_predicate('/css/cssom/'),
order: 91
},
csspos: {
name: '/css/css-position',
predicate: prefix_predicate('/css/css-position/'),
order: 92
},
cssflex: {
name: '/css/css-flexbox',
predicate: prefix_predicate('/css/css-flexbox/'),
order: 93
},
cssgrid: {
name: '/css/css-grid',
predicate: prefix_predicate('/css/css-grid/'),
order: 94
},
cssalign: {
name: '/css/css-align',
predicate: prefix_predicate('/css/css-align/'),
order: 95
},
csstext: {
name: '/css/css-text',
predicate: prefix_predicate('/css/css-text/'),
order: 96
},
gamepad: {
name: '/gamepad',
predicate: prefix_predicate('/gamepad/'),
order: 97
},
shadowdom: {
name: '/shadow-dom',
predicate: prefix_predicate('/shadow-dom/'),
order: 98
},
webcryptoapi: {
name: '/WebCryptoAPI',
predicate: prefix_predicate('/WebCryptoAPI/'),
order: 99
},
webxr: {
name: '/webxr',
predicate: prefix_predicate('/webxr/'),
order: 100
}
}
for (const [idx, folder] of CSS2_FOCUS_FOLDERS.entries()) {
const path = `/css/CSS2/${folder}/`
FOCUS_AREAS[folder] = {
name: `${path}`,
predicate: prefix_predicate(path),
order: idx + 3
}
}
export function get_focus_areas () {
const area_keys = []
const area_names = {}
for (const [key, area] of Object.entries(FOCUS_AREAS)) {
area_keys.push(key)
area_names[key] = area.name
}
area_keys.sort((a, b) => FOCUS_AREAS[a].order - FOCUS_AREAS[b].order)
return { area_keys, area_names }
}
export function score_run (run, against_run, focus_areas_map) {
const scores = {}
for (const area of Object.keys(FOCUS_AREAS)) {
scores[area] = {
total_tests: 0,
total_score: 0
}
}
for (const [test, { subtests }] of Object.entries(against_run.test_scores)) {
const areas = focus_areas_map[test]
for (const area of areas) {
scores[area].total_tests += 1
}
const run_test = run.test_scores[test]
// score new tests not present in older runs
if (!run_test) continue
const subtest_names = Object.keys(subtests)
if (!subtest_names.length) {
for (const area of areas) {
scores[area].total_score += run_test.score
}
} else {
let test_score = 0
for (const subtest of subtest_names) {
if (Object.hasOwn(run_test.subtests, subtest)) {
test_score += run_test.subtests[subtest].score
}
}
test_score /= subtest_names.length
for (const area of areas) {
scores[area].total_score += test_score
}
}
}
return Object.entries(scores).reduce((scores, [area, totals]) => {
scores[area] = 0
if (totals.total_tests !== 0) {
scores[area] = Math.floor(
1000 * totals.total_score / totals.total_tests
)
}
return scores
}, {})
}