/
validateConfig.spec.js
77 lines (66 loc) · 2.22 KB
/
validateConfig.spec.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
import makeConsoleMock from 'consolemock'
import validateConfig from '../lib/validateConfig'
describe('validateConfig', () => {
const originalConsole = global.console
beforeAll(() => {
global.console = makeConsoleMock()
})
beforeEach(() => {
global.console.clearHistory()
})
afterAll(() => {
global.console = originalConsole
})
it('should throw and should print validation errors for invalid config 1', () => {
const invalidConfig = 'test'
expect(() => validateConfig(invalidConfig)).toThrowErrorMatchingSnapshot()
})
it('should throw and should print validation errors for invalid config', () => {
const invalidConfig = {
foo: false
}
expect(() => validateConfig(invalidConfig)).toThrowErrorMatchingSnapshot()
})
it('should not throw and should print nothing for valid config', () => {
const validSimpleConfig = {
'*.js': ['eslint --fix', 'git add']
}
expect(() => validateConfig(validSimpleConfig)).not.toThrow()
expect(console.printHistory()).toMatchSnapshot()
})
it('should not throw and should print nothing for function task', () => {
expect(() =>
validateConfig({
'*.js': filenames => {
const files = filenames.join(' ')
return `eslint --fix ${files} && git add ${files}`
},
'*.css': [filenames => filenames.map(filename => `eslint --fix ${filename}`)]
})
).not.toThrow()
expect(console.printHistory()).toMatchSnapshot()
})
it('should throw when detecting deprecated advanced configuration', () => {
const advancedConfig = {
chunkSize: 10,
concurrent: false,
globOptions: { matchBase: false },
ignore: ['test.js'],
linters: {
'*.js': ['eslint']
},
relative: true,
renderer: 'silent',
subTaskConcurrency: 10
}
expect(() => validateConfig(advancedConfig)).toThrowErrorMatchingSnapshot()
expect(console.printHistory()).toMatchSnapshot()
})
it('should not throw when config contains deprecated key but with valid task', () => {
const stillValidConfig = {
concurrent: 'my command'
}
expect(() => validateConfig(stillValidConfig)).not.toThrow()
expect(console.printHistory()).toMatchSnapshot()
})
})