/
jslint-xml.js
126 lines (105 loc) · 4.19 KB
/
jslint-xml.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
/**
* @fileoverview Tests for JSLint XML reporter.
* @author Ian Christian Myers
*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var vows = require("vows"),
assert = require("assert"),
formatter = require("../../../lib/formatters/jslint-xml");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
vows.describe("formatter:jslint-xml").addBatch({
"when passed a single message": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo",
source: "foo"
}]
}],
"should return a string in JSLint XML format with 1 issue in 1 file": function(topic) {
var config = {
rules: { foo: 2 }
};
var result = formatter(topic, config);
assert.equal("<?xml version=\"1.0\" encoding=\"utf-8\"?><jslint><file name=\"foo.js\"><issue line=\"5\" char=\"10\" evidence=\"foo\" reason=\"Unexpected foo.\" /></file></jslint>", result);
}
},
"when passed a fatal error message": {
topic: [{
filePath: "foo.js",
messages: [{
fatal: true,
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo",
source: "foo"
}]
}],
"should return a string in JSLint XML format with 1 issue in 1 file": function(topic) {
var config = {}; // doesn't matter what's in the config for this test
var result = formatter(topic, config);
assert.equal("<?xml version=\"1.0\" encoding=\"utf-8\"?><jslint><file name=\"foo.js\"><issue line=\"5\" char=\"10\" evidence=\"foo\" reason=\"Unexpected foo.\" /></file></jslint>", result);
}
},
"when passed multiple messages": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo",
source: "foo"
}, {
message: "Unexpected bar.",
line: 6,
column: 11,
ruleId: "bar",
source: "bar"
}]
}],
"should return a string in JSLint XML format with 2 issues in 1 file": function(topic) {
var config = {
rules: { foo: 2, bar: 1 }
};
var result = formatter(topic, config);
assert.equal("<?xml version=\"1.0\" encoding=\"utf-8\"?><jslint><file name=\"foo.js\"><issue line=\"5\" char=\"10\" evidence=\"foo\" reason=\"Unexpected foo.\" /><issue line=\"6\" char=\"11\" evidence=\"bar\" reason=\"Unexpected bar.\" /></file></jslint>", result);
}
},
"when passed multiple files with 1 message each": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo",
source: "foo"
}]
}, {
filePath: "bar.js",
messages: [{
message: "Unexpected bar.",
line: 6,
column: 11,
ruleId: "bar",
source: "bar"
}]
}],
"should return a string in JSLint XML format with 2 issues in 2 files": function(topic) {
var config = {
rules: { foo: 2, bar: 1 }
};
var result = formatter(topic, config);
assert.equal("<?xml version=\"1.0\" encoding=\"utf-8\"?><jslint><file name=\"foo.js\"><issue line=\"5\" char=\"10\" evidence=\"foo\" reason=\"Unexpected foo.\" /></file><file name=\"bar.js\"><issue line=\"6\" char=\"11\" evidence=\"bar\" reason=\"Unexpected bar.\" /></file></jslint>", result);
}
}
}).export(module);