-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare-wpt-for-site.js
111 lines (84 loc) · 2.6 KB
/
prepare-wpt-for-site.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
import fs from "fs/promises";
import { rimraf } from "rimraf";
import wpt from "./site/_data/wpt.json" assert { type: "json" };
import features from "./site/_data/features.json" assert { type: "json" };
const GRAPH_DATA_DIR = "site/assets/wpt";
const MAIN_GRAPH_OUTPUT_FILE = `${GRAPH_DATA_DIR}/all_tests.json`;
function getBrowserName(code) {
return {
c: "chrome",
f: "firefox",
e: "edge",
s: "safari",
}[code];
}
function generateMainGraphData() {
const graphData = [];
for (let dateStr in wpt) {
const dateData = wpt[dateStr];
const totalPerBrowser = {};
for (let featureName in dateData) {
if (!features.find(({ id }) => id === featureName)) {
continue;
}
const featureData = dateData[featureName];
for (let browserCode in featureData) {
// Skip SHAs.
if (browserCode === "r") {
continue;
}
// Get complete browser names.
const browserName = getBrowserName(browserCode);
if (!totalPerBrowser[browserName]) {
totalPerBrowser[browserName] = {
passed: 0,
total: 0,
};
}
totalPerBrowser[browserName].passed += featureData[browserCode][0];
totalPerBrowser[browserName].total += featureData[browserCode][1];
}
}
graphData.push({
date: dateStr,
...totalPerBrowser,
});
}
return graphData;
}
function generateFeatureGraphData(featureID) {
const graphData = [];
for (let dateStr in wpt) {
const featureData = wpt[dateStr][featureID];
const perBrowser = {
date: dateStr
};
for (let browserCode in featureData) {
// Skip SHAs.
if (browserCode === "r") {
continue;
}
// Get complete browser names.
const browserName = getBrowserName(browserCode);
const passed = featureData[browserCode][0];
const total = featureData[browserCode][1];
perBrowser[browserName] = { passed, total };
}
graphData.push(perBrowser);
}
return graphData;
}
async function main() {
console.log("Deleting existing graph data ...");
await rimraf(GRAPH_DATA_DIR);
await fs.mkdir(GRAPH_DATA_DIR);
console.log("Generating data for the main graph ...");
const mainGraphData = generateMainGraphData();
await fs.writeFile(MAIN_GRAPH_OUTPUT_FILE, JSON.stringify(mainGraphData));
for (const { id } of features) {
console.log(`Generating data for the ${id} graph ...`);
const featureGraphData = generateFeatureGraphData(id);
await fs.writeFile(`${GRAPH_DATA_DIR}/${id}.json`, JSON.stringify(featureGraphData));
}
}
main();