-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact.test.js
59 lines (47 loc) · 1.45 KB
/
react.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
/* eslint-env jest */
'use strict'
const fs = require('fs')
const path = require('path')
const config = require('./react.js')
const { CLIEngine } = require('eslint')
const cli = new CLIEngine({
ignore: false,
useEslintrc: false,
configFile: path.resolve(__dirname, 'react.js'),
})
const testFile = filepath =>
new Promise((resolve, reject) => {
fs.readFile(filepath, 'utf-8', (err, file) => {
if (err) {
reject(err)
} else {
resolve(cli.executeOnText(file, filepath))
}
})
})
expect.addSnapshotSerializer({
print: val => JSON.stringify(val.replace(__dirname, '<PROJECT_ROOT>')),
test: val => typeof val === 'string',
})
describe('@simonkberg/eslint-config/react', () => {
it('should match the snapshot', () => expect(config).toMatchSnapshot())
it('should load config in eslint', async () => {
const result1 = await testFile(
path.resolve(__dirname, '__fixtures__/react.js')
)
expect(result1.errorCount).toBe(0)
expect(result1.warningCount).toBe(0)
})
it('should support jest environment', async () => {
const result1 = await testFile(
path.resolve(__dirname, '__fixtures__/__tests__/react.jsx')
)
expect(result1.errorCount).toBe(0)
expect(result1.warningCount).toBe(0)
const result2 = await testFile(
path.resolve(__dirname, '__fixtures__/react.test.jsx')
)
expect(result2.errorCount).toBe(0)
expect(result2.warningCount).toBe(0)
})
})