forked from ScottLogic/openapi-forge-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testResultParser.js
42 lines (38 loc) · 1.28 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
function parseTestResultNumber(number) {
const result = parseInt(number);
return isNaN(result) ? 0 : result;
}
function parse(durationLine, resultLine) {
// Extract the duration of the testing from stdout.
const durationMatch = durationLine.match(/^(\d+)m(\d+)\.\d+s/);
let result;
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 = resultLine.match(
/^(\d+)\sscenarios?\s\(((\d+)\sfailed)?(,\s)?((\d+)\sundefined)?(,\s)?((\d+)\spassed)?\)/
);
if (resultMatch) {
result = {
scenarios: parseTestResultNumber(resultMatch[1]),
passed: parseTestResultNumber(resultMatch[9]),
skipped: 0,
undef: parseTestResultNumber(resultMatch[6]),
failed: parseTestResultNumber(resultMatch[3]),
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,
};