forked from ScottLogic/openapi-forge-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestResultParser.js
51 lines (44 loc) · 1.54 KB
/
testResultParser.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
function parseTestResultNumber(number) {
const result = parseInt(number);
return isNaN(result) ? 0 : result;
}
function parse(results) {
const ll = results.length;
const failLineRegex = /\d+\)\sScenario:\s(.*)\s#.*/;
let failures = [];
let rr;
for (let xx = 0; xx < ll; xx++) {
if ((rr = results[xx].match(failLineRegex))) failures.push(rr[1]);
}
let result = {};
result.failures = failures;
// Extract the duration of the testing from stdout.
const durationMatch = results[ll - 2].match(/^(\d+)m(\d+)\.\d+s/);
if (durationMatch) {
// Format the duration
let time = "";
if (durationMatch[1] !== "0" && durationMatch[1] !== "")
time = `${durationMatch[1]}m`;
time = `${time}${durationMatch[2]}s`;
// Extract the results of the testing from stdout. In stdout is a count of tests and their outcomes.
const resultMatch = results[ll - 4].match(
/^(\d+)\sscenarios?\s\(((\d+)\sfailed)?(,\s)?((\d+)\sundefined)?(,\s)?((\d+)\spassed)?\)/
);
if (resultMatch) {
result.scenarios = parseTestResultNumber(resultMatch[1]);
result.passed = parseTestResultNumber(resultMatch[9]);
result.skipped = 0;
result.undef = parseTestResultNumber(resultMatch[6]);
result.failed = parseTestResultNumber(resultMatch[3]);
result.time = time;
} else {
throw new Error(`Could not parse the results of the TypeScript testing.`);
}
} else {
throw new Error(`Could not parse the duration of the TypeScript testing.`);
}
return result;
}
module.exports = {
parse,
};