-
Notifications
You must be signed in to change notification settings - Fork 3
/
resultConverter.js
55 lines (44 loc) · 1.26 KB
/
resultConverter.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
var funMap = require('fun-map');
function splitByNewLine(text) {
return text.split('\n').filter(Boolean);
}
function splitItemsByNewLine(texts) {
return texts.reduce(function(acc, item) {
return acc.concat(splitByNewLine(item));
}, []);
}
function simplifyResult(result) {
var testResult = {
log: splitItemsByNewLine(result.log || []),
time: result.time
};
if (result.skipped) {
testResult.status = 'SKIPPED';
} else {
testResult.status = result.success ? 'PASSED' : 'FAILED';
testResult.noExpectationsWarning = result.success && result.executedExpectationsCount === 0;
}
return testResult;
}
function getPathArray(result) {
var path = result.suite.slice();
path.push(result.description);
return path;
}
function reduceToObject(accumulator, result) {
var simplifiedResult = simplifyResult(result);
var path = getPathArray(result);
return funMap.assocInM(accumulator, path, simplifiedResult);
}
function convertResults(results) {
return results.reduce(reduceToObject, {});
}
function convertErrors(errors) {
return {"__BROWSER_ERRORS__": splitItemsByNewLine(errors)};
}
module.exports = {
simplifyResult: simplifyResult,
reduceToObject: reduceToObject,
convertResults: convertResults,
convertErrors: convertErrors
};