forked from puppeteer/ispuppeteerwebdriverbidiready
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess-data.js
49 lines (46 loc) · 1.67 KB
/
preprocess-data.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
const fs = require('fs');
async function main() {
const files = fs.readdirSync('./data');
const data = files.filter(file => file.endsWith('.json')).sort().map(file => {
const parts = file.split('-');
if (parts.length === 1) {
parts.unshift('firefox');
}
parts[1] = parts[1].split('.').shift();
const [browser, timestamp] = parts;
const stats = JSON.parse(fs.readFileSync('./data/' + file, 'utf-8')).stats;
// Since few tests are supported we don't report the skipped tests to make
// sure the chart is readable.
const counts = {
passing: stats.passes,
failing: stats.failures,
skipping: 0, // stats.pending,
total: stats.tests,
}
counts.unsupported = 0; // counts.total - (counts.passing + counts.failing + counts.skipping);
return {
browser,
date: Number(timestamp) * 1000,
counts,
}
});
const groupByDate = new Map();
for (const item of data) {
if (!groupByDate.has(item.date)) {
groupByDate.set(item.date, []);
}
groupByDate.get(item.date).push(item);
}
const mappedData = [];
for (const date of Array.from(groupByDate.keys()).sort()) {
mappedData.push({
date,
chromeCounts: groupByDate.get(date).find(item => item.browser === 'chrome')?.counts || {passing: 0, failing: 0, skipping: 0, total: 0, unsupported: 0},
firefoxCounts: groupByDate.get(date).find(item => item.browser === 'firefox')?.counts || {passing: 0, failing: 0, skipping: 0, total: 0, unsupported: 0},
// TODO: extend the object here for more browsers.
});
}
fs.writeFileSync('data.json', JSON.stringify(mappedData, null, 2));
console.log(mappedData);
}
main();