-
Notifications
You must be signed in to change notification settings - Fork 61
/
jest-setup.js
42 lines (36 loc) · 870 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
42
const stylelint = require('stylelint');
// eslint-disable-next-line import/no-extraneous-dependencies
const getTestRule = require('jest-preset-stylelint/getTestRule');
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,
quietDeprecationWarnings: true,
})
.then((data) => {
const { invalidOptionWarnings } = data.results[0];
if (input.valid) {
expect(invalidOptionWarnings.length).toBe(0);
} else {
expect(invalidOptionWarnings[0].text).toBe(input.message);
}
});
});
};