-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
85 lines (71 loc) · 2.68 KB
/
index.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
const child_process = require('child_process')
describe('eslint config', () => {
// #region Pass
it('should pass if there are no errors', () => {
const output = child_process
.execSync('yarn eslint -f "json" --no-ignore test-cases/pass.js')
.toString()
expect(output.includes('"errorCount":0')).toBeTruthy()
expect(output.includes('"fatalErrorCount":0')).toBeTruthy()
expect(output.includes('"warningCount":0')).toBeTruthy()
expect(output.includes('"fixableErrorCount":0')).toBeTruthy()
expect(output.includes('"fixableWarningCount":0')).toBeTruthy()
})
// #endregion
// #region Warn
it('should warn if console is used', () => {
const output = child_process
.execSync(
'yarn eslint -f "json" --no-ignore test-cases/warn-no-console.js'
)
.toString()
expect(output.includes('"ruleId":"no-console"')).toBeTruthy()
expect(output.includes('"errorCount":0')).toBeTruthy()
expect(output.includes('"warningCount":1')).toBeTruthy()
})
it('should warn if var is used', () => {
const output = child_process
.execSync('yarn eslint -f "json" --no-ignore test-cases/warn-no-var.js')
.toString()
expect(output.includes('"ruleId":"no-var"')).toBeTruthy()
expect(output.includes('"errorCount":0')).toBeTruthy()
expect(output.includes('"warningCount":1')).toBeTruthy()
})
it('should warn if braces are not used', () => {
const output = child_process
.execSync('yarn eslint -f "json" --no-ignore test-cases/warn-curly.js')
.toString()
expect(output.includes('"ruleId":"curly"')).toBeTruthy()
expect(output.includes('"errorCount":0')).toBeTruthy()
expect(output.includes('"warningCount":2')).toBeTruthy()
})
it('should warn if destructuring is not used', () => {
const output = child_process
.execSync(
'yarn eslint -f "json" --no-ignore test-cases/warn-prefer-destructuring.js'
)
.toString()
expect(output.includes('"ruleId":"prefer-destructuring"')).toBeTruthy()
expect(output.includes('"errorCount":0')).toBeTruthy()
expect(output.includes('"warningCount":1')).toBeTruthy()
})
// #endregion
// #region Fail
it('should fail if debugger is used', () => {
const call = () =>
child_process.execSync(
'yarn eslint -f "json" --no-ignore test-cases/error-no-debugger.js'
)
expect(call).toThrow()
let output = null
try {
call()
} catch (err) {
output = err.stdout.toString()
expect(output.includes('"ruleId":"no-debugger"')).toBeTruthy()
expect(output.includes('"errorCount":1')).toBeTruthy()
expect(output.includes('"warningCount":0')).toBeTruthy()
}
})
// #endregion
})