-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathno-only.spec.js
53 lines (45 loc) · 1.24 KB
/
no-only.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
const path = require('path')
const eslint = require('eslint')
const plugin = require('..')
const _ = require('lodash')
const { expect } = require('chai')
const ruleName = 'no-only'
const pluginName = '__plugin__'
const ESLint = eslint.ESLint
async function execute (file, options = {}) {
const defaultConfig = {
fix: true,
ignore: false,
useEslintrc: false,
baseConfig: {
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
[`${pluginName}/${ruleName}`]: ['error'],
},
plugins: [pluginName],
},
plugins: {
[pluginName]: plugin,
},
}
const opts = _.defaultsDeep(options, defaultConfig)
const cli = new ESLint(opts)
const results = await cli.lintFiles([path.join(__dirname, file)])
return results[0]
}
describe('no-only', () => {
it('lint js with only', async () => {
const filename = './fixtures/with-only.js'
const result = await execute(filename, {
fix: true,
})
expect(result.errorCount).eq(3)
expect(result.messages[0].message).to.contain('it')
expect(result.messages[1].message).to.contain('describe')
expect(result.messages[2].message).to.contain('context')
expect(result.output).not.exist
})
})