forked from hudochenkov/stylelint-order
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest-setup.js
41 lines (35 loc) · 816 Bytes
/
jest-setup.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
import stylelint from 'stylelint';
// eslint-disable-next-line import/no-extraneous-dependencies
import { getTestRule } from 'jest-preset-stylelint';
global.testRule = getTestRule({ plugins: ['./'] });
global.testConfig = (input) => {
let testFn;
if (input.only) {
testFn = test.only;
} else if (input.skip) {
testFn = test.skip;
} else {
testFn = test;
}
testFn(input.description, () => {
const config = {
plugins: ['./'],
rules: {
[input.ruleName]: input.config,
},
};
return stylelint
.lint({
code: '',
config,
})
.then((data) => {
const { invalidOptionWarnings } = data.results[0];
if (input.valid) {
expect(invalidOptionWarnings.length).toBe(0);
} else {
expect(invalidOptionWarnings[0].text).toBe(input.message);
}
});
});
};