-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults.js
133 lines (125 loc) · 7.3 KB
/
results.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const xpath = require("xpath");
const tests = require("./classes/tests");
const core = require("./core");
const dom = require("xmldom").DOMParser;
class Results {
constructor() {}
/**
* @param {string} content
* @returns {ITestResult[]}
*/
getSteps(content) {
/** @type {ITestResult[]} */
const results = [];
const doc = new dom().parseFromString(content);
// https://svn.apache.org/repos/asf/jmeter/tags/v2_4/docs/usermanual/listeners.html .. format description
const nodes = xpath.select("//*[@lb]", doc);
nodes.forEach((n) =>
results.push({
info: {
label: n.getAttribute("lb"),
asserts: xpath
.select("./assertionResult", n)
.filter((fn) => xpath.select1("./failure", fn).textContent == "true")
.map((fn) => xpath.select1("./failureMessage", fn).textContent.replace(/[\r\n]+/g, " ")),
responseData: xpath.select1("./responseData", n).textContent,
},
success: n.getAttribute("s") == "true",
})
);
return results;
}
printInitReport(resultsFile) {
const steps = this.getSteps(core.readTextFile(resultsFile));
const failed = steps.filter((step) => !step.success && !step.info.label.match(/\sT[0-9]+$/)).map((step) => step.info);
tests.showFailedSteps(failed, true);
}
printReport(MR, newPassed, newFailed, knownFailed, allPassed, startedDate) {
core.writeTextFile(
`${MR.folder}/${MR.server}/src/test/jmeter/logs/testResults.json`,
JSON.stringify(
{
PASSED: newPassed,
FAILED_NEW: newFailed,
FAILED_KNOWN: knownFailed,
},
null,
2
)
);
core.showMessage("\n\n======== TESTS SUMMARY =======");
const now = new Date();
console.log("Started:", startedDate.toLocaleString());
console.log("Finished:", now.toLocaleString());
console.log("=>", this.formatTime((now.getTime() - startedDate.getTime()) / 1000), "minutes");
tests.showFailedTests(newPassed, newFailed);
if (Object.keys(newFailed).length || Object.keys(newPassed).length) {
core.showError("Tests failed. Watch message above.", false);
} else {
core.showSuccess("All tests passed as expected.");
core.showSuccess("");
core.showSuccess(" ████ ");
core.showSuccess(" ███ ██ ");
core.showSuccess(" ██ █ ");
core.showSuccess(" ██ ██ ");
core.showSuccess(" ██ ███ ");
core.showSuccess(" ██ ██ ");
core.showSuccess(" ██ ███ ");
core.showSuccess(" ██ ██ ");
core.showSuccess(" ███████ ██ ");
core.showSuccess(" █████ ███ ██ ");
core.showSuccess(" ██ ████ ██████ ");
core.showSuccess(" ██ ████ ███ ██");
core.showSuccess(" ██ ███ ██");
core.showSuccess(" ██████████ ███ ██");
core.showSuccess(" ██ ████ ██");
core.showSuccess(" ███████████ ██ ██");
core.showSuccess(" ██ ████ ██████ ");
core.showSuccess(" ██████████ ██ ███ ██ ");
core.showSuccess(" ██ ████ ███ ");
core.showSuccess(" █████████████ ");
core.showSuccess("");
}
core.showSuccess(`Passed: ${Object.values(allPassed).reduce((p, c) => p + c.length, 0)}`);
Object.entries(allPassed).forEach(([key, passed]) => {
core.showSuccess(` - ${key}: ${passed.length}`);
});
core.showWarning(`Failed and fix in progress: ${Object.values(knownFailed).reduce((p, c) => p + c.length, 0)}`);
const failedCount = Object.values(newFailed).reduce((p, c) => p + c.length, 0);
if (failedCount) {
core.showError(`New failed tests: ${failedCount}`, false);
}
if (Object.keys(newFailed).length || Object.keys(newPassed).length) {
core.showError("", false);
core.showError(" █████ █████", false);
core.showError(" ███████ ███████", false);
core.showError(" ███████ ███████████████ ███████", false);
core.showError(" ████████ ███████████████████ ████████", false);
core.showError(" █████ █████████████████████ █████", false);
core.showError(" █████ ███████████████████████ █████", false);
core.showError(" ██ █████████████████████████ ██", false);
core.showError(" ███████ ██████ ██████", false);
core.showError(" ██████ ████ █████", false);
core.showError(" ██████ ████ █████", false);
core.showError(" ██████ ██████ █████", false);
core.showError(" ███████████ ██████████", false);
core.showError(" ██████████ █████████", false);
core.showError(" ██ ███████████████████ ██", false);
core.showError(" ████ ████ █ █ █ █ ████ ████", false);
core.showError(" █████ ███ █ █ █ █ ███ █████", false);
core.showError(" █████ █████████████ █████", false);
core.showError(" ████ ███████████ ████", false);
core.showError(" █████ ███████ █████", false);
core.showError(" ███████ ███████", false);
core.showError(" █████ █████", false);
core.showError("", false);
}
}
formatTime(totalSeconds) {
totalSeconds = Math.round(totalSeconds);
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds - minutes * 60;
return `${minutes}:${seconds.toString().padStart(2, "0")}`;
}
}
module.exports = new Results();