/
integration.test.js
196 lines (165 loc) · 4.53 KB
/
integration.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'use strict';
const lessSyntax = require('postcss-less');
const path = require('path');
const postcss = require('postcss');
const sassSyntax = require('postcss-sass');
const scssSyntax = require('postcss-scss');
const stylelint = require('..');
const config = {
rules: {
'block-opening-brace-newline-after': 'always',
'declaration-property-unit-disallowed-list': {
width: ['px', 'em'],
},
'color-no-invalid-hex': [
true,
{
severity: 'warning',
message: 'You made a mistake',
},
],
'function-allowed-list': null,
'function-disallowed-list': ['calc'],
'no-duplicate-selectors': true,
},
};
const css = `
a { background: pink; }
b {
height: 1rem;
display: block;
width: 10px;
color: #zzz;
}
/* stylelint-disable color-no-invalid-hex */
.foo {
color: #yyy;
}
/* stylelint-enable */
.bar:before {
color: #mmm;
height: calc(1rem - 100%)
}
`;
describe('integration test expecting warnings', () => {
let result;
beforeEach(() => {
return postcss()
.use(stylelint(config))
.process(css, { from: undefined })
.then((data) => (result = data));
});
it('number and type', () => {
expect(result.messages).toHaveLength(5);
expect(result.messages.every((m) => m.type === 'warning')).toBeTruthy();
expect(result.messages.every((m) => m.plugin === 'stylelint')).toBeTruthy();
});
it('block-opening-brace-newline-after - string primary option', () => {
const error = result.messages.find((msg) => msg.rule === 'block-opening-brace-newline-after');
expect(error).toBeTruthy();
expect(error.text).toBe('Expected newline after "{" (block-opening-brace-newline-after)');
expect(error.severity).toBe('error');
});
it('declaration-property-unit-disallowed-list - object primary option', () => {
const error = result.messages.find(
(msg) => msg.rule === 'declaration-property-unit-disallowed-list',
);
expect(error).toBeTruthy();
expect(error.text).toBe(
'Unexpected unit "px" for property "width" (declaration-property-unit-disallowed-list)',
);
expect(error.severity).toBe('error');
});
it('color-no-invalid-hex - true primary option', () => {
const errors = result.messages.filter((msg) => msg.rule === 'color-no-invalid-hex');
expect(errors).toHaveLength(2);
errors.forEach((error) => {
expect(error.text).toBe('You made a mistake');
expect(error.severity).toBe('warning');
});
});
it('function-disallowed-list - array primary option', () => {
const error = result.messages.find((msg) => msg.rule === 'function-disallowed-list');
expect(error).toBeTruthy();
expect(error.text).toBe('Unexpected function "calc" (function-disallowed-list)');
expect(error.severity).toBe('error');
});
});
it('Less integration test', () => {
const less = `.foo(@bar) {
color: @bar;
}
`;
return postcss()
.use(stylelint({ rules: {} }))
.process(less, { syntax: lessSyntax, from: undefined })
.then((result) => {
expect(result.messages).toHaveLength(0);
});
});
it('Sass integration test', () => {
const sass = `.foo-#{variable}
color: $color`;
return postcss()
.use(stylelint({ rules: {} }))
.process(sass, { syntax: sassSyntax, from: undefined })
.then((result) => {
expect(result.messages).toHaveLength(0);
});
});
it('Scss integration test', () => {
const scss = `.foo-#{variable} {
color: $color;
}
`;
return postcss()
.use(stylelint({ rules: {} }))
.process(scss, { syntax: scssSyntax, from: undefined })
.then((result) => {
expect(result.messages).toHaveLength(0);
});
});
describe('integration test null option', () => {
let results;
beforeEach(() => {
return stylelint
.lint({
config: {
extends: [path.join(__dirname, 'fixtures/config-no-pixels')],
rules: {
'unit-disallowed-list': null,
},
},
code: 'a { top: 10px; }',
})
.then((data) => (results = data.results));
});
it('no invalid option warnings', () => {
expect(results[0].invalidOptionWarnings).toHaveLength(0);
});
it('no warnings', () => {
expect(results[0].warnings).toHaveLength(0);
});
});
describe('integration test [null] option', () => {
let results;
beforeEach(() => {
return stylelint
.lint({
config: {
extends: [path.join(__dirname, 'fixtures/config-no-pixels')],
rules: {
'unit-disallowed-list': [null],
},
},
code: 'a { top: 10px; }',
})
.then((data) => (results = data.results));
});
it('no invalid option warnings', () => {
expect(results[0].invalidOptionWarnings).toHaveLength(0);
});
it('no warnings', () => {
expect(results[0].warnings).toHaveLength(0);
});
});