-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest.js
67 lines (64 loc) · 1.66 KB
/
test.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
var test = require('tape');
var xml2js = require('xml2js');
var checkstyleFormatter = require('./index');
var mockResults = [
{
source: 'path/to/fileA.css',
errored: false,
warnings: [
{
line: 3,
column: 8,
rule: 'block-no-empty',
severity: 'warning',
text: 'No empty block!',
},
],
},
{
source: 'path/to/fileB.css',
errors: true,
warnings: [
{
line: 1,
column: 2,
rule: 'foo',
severity: 'error',
text: 'foo text',
},
{
line: 2,
column: 5,
rule: 'bar',
severity: 'error',
text: 'bar text',
},
],
},
{
source: 'path/to/fileC.css',
errors: false,
warnings: [],
},
];
var expectedXml = '<?xml version="1.0" encoding="utf-8"?>\n' +
'<checkstyle version="4.3">\n' +
' <file name="path/to/fileA.css">\n' +
' <error source="stylelint.rules.block-no-empty" line="3" column="8" severity="warning" message="No empty block!" />\n' +
' </file>\n' +
' <file name="path/to/fileB.css">\n' +
' <error source="stylelint.rules.foo" line="1" column="2" severity="error" message="foo text" />\n' +
' <error source="stylelint.rules.bar" line="2" column="5" severity="error" message="bar text" />\n' +
' </file>\n' +
' <file name="path/to/fileC.css"></file>\n' +
'</checkstyle>';
test('output XML string', function(t) {
var output = checkstyleFormatter(mockResults);
t.equal(output, expectedXml, "matches expectation");
t.doesNotThrow(function() {
xml2js.parseString(output, function(err) {
if (err) throw err;
});
}, "is valid XML");
t.end()
});