Created
February 1, 2018 14:12
-
-
Save foolip/42e5e00f6676588378bd4c47965617b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const fs = require('fs') | |
// Create a simplified view of the results: a map of test names (~=filename) to | |
// an array of maps from subtest name to status. | |
function readResultsAsMap(filename) { | |
const results = JSON.parse(fs.readFileSync(filename)).results; | |
const testMap = new Map; | |
for (const result of results) { | |
const testName = result.test; | |
const subtestMap = new Map; | |
console.assert(!testMap.has(testName)); | |
testMap.set(testName, subtestMap); | |
for (const subtest of result.subtests) { | |
console.assert(!subtestMap.has(subtest.name)); | |
subtestMap.set(subtest.name, subtest.status); | |
} | |
} | |
return testMap; | |
} | |
function mergeMaps(a, b) { | |
// merge and sort the names | |
const nameSet = new Set; | |
for (const name of a.keys()) | |
nameSet.add(name); | |
for (const name of b.keys()) | |
nameSet.add(name); | |
const names = Array.from(nameSet); | |
names.sort(); | |
function getResult(group, testName, subtestName) { | |
const test = group.get(testName); | |
if (test) | |
return test.get(subtestName); | |
return undefined; | |
} | |
const tests = new Map; | |
for (const name of names) { | |
// retain the order of subtests, appending any extra in b at the end. | |
const subtests = new Map; | |
function mergeSubtestNames(group) { | |
const groupSubtests = group.get(name); | |
if (groupSubtests) { | |
for (const subtestName of groupSubtests.keys()) | |
subtests.set(subtestName, undefined); | |
} | |
} | |
mergeSubtestNames(a); | |
mergeSubtestNames(b); | |
for (const subtestName of subtests.keys()) | |
subtests.set(subtestName, [getResult(a, name, subtestName), getResult(b, name, subtestName)]); | |
tests.set(name, subtests); | |
} | |
return tests; | |
} | |
const chrome = readResultsAsMap('chrome57.json'); | |
const uc = readResultsAsMap('uc.json'); | |
const merged = mergeMaps(chrome, uc) | |
for (const [testName, subtests] of merged) { | |
for (const [subtestName, [chrome, uc]] of subtests) { | |
if (chrome !== uc) | |
console.log([testName, subtestName, chrome, uc].map(x => String(x).replace(/\s+/g, ' ')).join('\t')) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment