This repository has been archived by the owner on Dec 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathjshint-junit-xml-formatter.js
76 lines (67 loc) · 1.96 KB
/
jshint-junit-xml-formatter.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
/*jshint node:true */
/* Adapted from the default JSHint xml formatter by Derek Prior
* http://prioritized.net
*
* Source, documentation, and license available at:
* https://github.com/derekprior/jshint-junit-xml-formatter
*/
module.exports =
{
reporter: function (results)
{
"use strict";
var suite = 'jshint';
var files = {};
var out = [];
var pairs = {
"&": "&",
'"': """,
"'": "'",
"<": "<",
">": ">"
};
function encode(s) {
for (var r in pairs) {
if (typeof(s) !== "undefined") {
s = s.replace(new RegExp(r, "g"), pairs[r]);
}
}
return s || "";
}
function failure_message(failures) {
var count = failures.length;
if (count === 1) {
return "1 JSHINT Failure";
} else {
return count + " JSHint Failures";
}
}
function failure_details(failures) {
var msg = [];
var item;
for (var i = 0; i < failures.length; i++) {
item = failures[i];
msg.push(i+1 + ". line " + item.line + ", char " + item.character + ": " + encode(item.reason));
}
return msg.join("\n");
}
results.forEach(function (result) {
result.file = result.file.replace(/^\.\//, '');
if (!files[result.file]) {
files[result.file] = [];
}
files[result.file].push(result.error);
});
out.push("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
out.push("<testsuite name=\"" + suite + "\" tests=\"" + Object.keys(files).length + "\" failures=\"" + results.length + "\" errors=\"0\" >");
for (var file in files) {
out.push("\t<testcase name=\"" + file + "\">");
out.push("\t\t<failure message=\"" + failure_message(files[file]) + "\" >");
out.push(failure_details(files[file]));
out.push("\t\t</failure>");
out.push("\t</testcase>");
}
out.push("</testsuite>");
process.stdout.write(out.join("\n") + "\n");
}
};