forked from davidtheclark/stylelint-checkstyle-formatter
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest.js
More file actions
141 lines (132 loc) · 4.25 KB
/
Copy pathtest.js
File metadata and controls
141 lines (132 loc) · 4.25 KB
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
134
135
136
137
138
139
140
141
const tape = require('tape');
const xml2js = require('xml2js');
const stylelinitJunitFormatter = require('./index');
const mockPassingTest = [
{
source: 'path/to/fileA.css',
errored: false,
warnings: [],
deprecations: [],
invalidOptionWarnings: [],
ignored: false,
},
{
source: 'path/to/fileB.css',
errored: false,
warnings: [],
deprecations: [],
invalidOptionWarnings: [],
ignored: false,
},
{
source: 'path/to/fileC.css',
errored: false,
warnings: [],
deprecations: [],
invalidOptionWarnings: [],
ignored: false,
},
];
const expectedPassingXml = `<?xml version="1.0" encoding="utf-8"?>
<testsuites package="stylelint.rules">
<testsuite name="path/to/fileA.css" failures="0" errors="0" tests="1">
<testcase name="stylelint.passed"/>
</testsuite>
<testsuite name="path/to/fileB.css" failures="0" errors="0" tests="1">
<testcase name="stylelint.passed"/>
</testsuite>
<testsuite name="path/to/fileC.css" failures="0" errors="0" tests="1">
<testcase name="stylelint.passed"/>
</testsuite>
</testsuites>`;
const mockFailingTest = [
{
source: 'path/to/fileA.css',
errored: false,
warnings: [],
deprecations: [],
invalidOptionWarnings: [],
ignored: false,
},
{
source: 'path/to/fileB.css',
errored: true,
warnings: [
{
line: 7,
column: 3,
rule: 'declaration-block-properties-order',
severity: 'error',
text: 'Expected quot;colorquot; to come before quot;font-weightquot; (declaration-block-properties-order)',
},
{
line: 8,
column: 3,
rule: 'shorthand-property-no-redundant-values',
severity: 'error',
text: 'Unexpected longhand value #39;0 2rem 1.5rem 2rem#39; instead of #39;0 2rem 1.5rem#39; (shorthand-property-no-redundant-values)',
},
],
deprecations: [],
invalidOptionWarnings: [],
ignored: false,
},
{
source: 'path/to/fileC.css',
errored: false,
warnings: [],
deprecations: [],
invalidOptionWarnings: [],
ignored: false,
},
];
const expectedFailingXml = `<?xml version="1.0" encoding="utf-8"?>
<testsuites package="stylelint.rules">
<testsuite name="path/to/fileA.css" failures="0" errors="0" tests="1">
<testcase name="stylelint.passed"/>
</testsuite>
<testsuite name="path/to/fileB.css" failures="2" errors="2" tests="2">
<testcase name="declaration-block-properties-order">
<failure type="error" message="Expected quot;colorquot; to come before quot;font-weightquot; (declaration-block-properties-order)">On line 7, column 3 in path/to/fileB.css</failure>
</testcase>
<testcase name="shorthand-property-no-redundant-values">
<failure type="error" message="Unexpected longhand value #39;0 2rem 1.5rem 2rem#39; instead of #39;0 2rem 1.5rem#39; (shorthand-property-no-redundant-values)">On line 8, column 3 in path/to/fileB.css</failure>
</testcase>
</testsuite>
<testsuite name="path/to/fileC.css" failures="0" errors="0" tests="1">
<testcase name="stylelint.passed"/>
</testsuite>
</testsuites>`;
const mockEmptyTests = [];
const expectedEmptyXml = `<?xml version="1.0" encoding="utf-8"?>
<testsuites package="stylelint.rules"/>`;
tape('It outputs a correct .xml for passing testsuites', (test) => {
const output = stylelinitJunitFormatter(mockPassingTest);
test.equal(output, expectedPassingXml, 'It matches expectation');
test.doesNotThrow(() => {
xml2js.parseString(output, (error) => {
if (error) throw error;
});
}, 'It outputs valid xml');
test.end();
});
tape('It outputs a correct .xml for failing testsuites', (test) => {
const output = stylelinitJunitFormatter(mockFailingTest);
test.equal(output, expectedFailingXml, 'It matches expectation');
test.doesNotThrow(() => {
xml2js.parseString(output, (error) => {
if (error) throw error;
});
}, 'It outputs valid xml');
test.end();
});
tape('It outputs a correct .xml for empty testsuites', (test) => {
const output = stylelinitJunitFormatter(mockEmptyTests);
test.equal(output, expectedEmptyXml, 'It matches expectation');
test.doesNotThrow(() => {
xml2js.parseString(output, (error) => {
if (error) throw error;
});
}, 'It outputs valid xml');
test.end();
});