-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract data interoplation logic to separate files
- Loading branch information
1 parent
0243431
commit 9e07df3
Showing
4 changed files
with
74 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = function compareVersions(a, b) { | ||
var vA = a.version; | ||
var vB = b.version; | ||
|
||
if (!vA && !vB) return 0; | ||
if (!vB) return 1; | ||
if (!vA) return -1; | ||
|
||
for (var i = 0; i < vA.length && i < vB.length; i++) { | ||
if (vA[i] === "tp" && vB[i] === "tp") continue; | ||
if (vA[i] === "tp") return 1; | ||
if (vB[i] === "tp") return -1; | ||
if (vA[i] > vB[i]) return 1; | ||
if (vA[i] < vB[i]) return -1; | ||
} | ||
|
||
if (vA.length > vB.length) return 1; | ||
if (vA.length < vB.length) return -1; | ||
|
||
return 0; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var parseEnvsVersions = require("./parse-envs-versions"); | ||
|
||
module.exports = function interpolateAllResults(tests, envs) { | ||
var envsTree = buildEnvsTree(envs); | ||
|
||
tests.forEach(function (t) { | ||
// Calculate the result totals for tests which consist solely of subtests. | ||
[].concat(t.subtests || t).forEach(function (e) { | ||
interpolateTestResults(e.res, envsTree); | ||
}); | ||
}); | ||
}; | ||
|
||
function interpolateTestResults(res, envsTree) { | ||
var bid, prevBid; | ||
for (bid in envsTree) { | ||
if (res[bid] !== undefined) continue; | ||
|
||
prevBid = bid; | ||
do { | ||
prevBid = envsTree[prevBid]; | ||
} while (prevBid !== null && res[prevBid] === undefined); | ||
|
||
if (prevBid !== null) res[bid] = res[prevBid]; | ||
} | ||
} | ||
|
||
// This function returns an object mapping "browser id" -> "parent browser id" | ||
function buildEnvsTree(data) { | ||
var result = {}; | ||
var envs = parseEnvsVersions(data); | ||
|
||
Object.keys(envs).forEach(function (name) { | ||
var id = envs[name][0].id; | ||
result[id] = data[id].equals || null; | ||
|
||
for (var i = 1; i < envs[name].length; i++) { | ||
id = envs[name][i].id; | ||
if (data[id].equals === false) result[id] = null; | ||
else result[id] = data[id].equals || envs[name][i - 1].id; | ||
} | ||
}); | ||
|
||
return result; | ||
} |
This file contains 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
This file contains 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