/
stylelintignore.test.js
120 lines (107 loc) · 2.95 KB
/
stylelintignore.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
'use strict';
const path = require('path');
const replaceBackslashes = require('../replaceBackslashes');
const standalone = require('../../standalone');
describe('stylelintignore', () => {
let actualCwd;
let results;
const fixturesPath = path.join(__dirname, './fixtures');
beforeEach(() => {
actualCwd = process.cwd();
process.chdir(__dirname);
});
afterEach(() => {
process.chdir(actualCwd);
});
describe('standalone with .stylelintignore file ignoring one file', () => {
beforeEach(() => {
return standalone({
files: [
replaceBackslashes(`${fixturesPath}/empty-block.css`),
replaceBackslashes(`${fixturesPath}/invalid-hex.css`),
],
config: {
extends: [
`${fixturesPath}/config-block-no-empty`,
`${fixturesPath}/config-color-no-invalid-hex`,
],
},
}).then((data) => (results = data.results));
});
it('one file read', () => {
expect(results).toHaveLength(1);
});
it('empty-block.css not read', () => {
expect(/empty-block\.css/.test(results[0].source)).toBe(false);
});
it('color-no-invalid-hex.css read', () => {
expect(/invalid-hex\.css/.test(results[0].source)).toBe(true);
});
it('color-no-invalid-hex.css linted', () => {
expect(results[0].warnings).toHaveLength(1);
});
});
describe('standalone with .stylelintignore file ignoring codeFilename', () => {
it('ignored file is ignored', () => {
return standalone({
code: '.bar {}',
codeFilename: `${fixturesPath}/empty-block.css`,
ignorePath: path.join(__dirname, '.stylelintignore'),
config: {
extends: `${fixturesPath}/config-block-no-empty`,
},
}).then((data) => {
expect(data).toEqual({
errored: false,
output: '[]',
results: [],
});
});
});
it('not ignored file is linted', () => {
return standalone({
code: '.bar {}',
codeFilename: `${fixturesPath}/empty-block.css`,
ignorePath: path.join(__dirname, '.stylelintignore-empty'),
config: {
extends: `${fixturesPath}/config-block-no-empty`,
},
}).then((data) => {
expect(data).toMatchObject({
errored: true,
output: expect.stringContaining('Unexpected empty block (block-no-empty)'),
results: expect.any(Array),
});
});
});
it('ignored file with syntax error is ignored', () => {
return standalone({
code: 'var a = {',
codeFilename: `test.js`,
ignorePath: path.join(__dirname, '.stylelintignore2'),
config: {
extends: `${fixturesPath}/config-block-no-empty`,
},
}).then((data) => {
expect(data).toEqual({
errored: false,
output: '[]',
results: [],
});
});
});
it('ignored file with syntax error is ignored and there is no config', () => {
return standalone({
code: 'var a = {',
codeFilename: `test.js`,
ignorePath: path.join(__dirname, '.stylelintignore2'),
}).then((data) => {
expect(data).toEqual({
errored: false,
output: '[]',
results: [],
});
});
});
});
});