-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.test.js
35 lines (27 loc) · 1018 Bytes
/
eslint.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
import test from 'ava';
import eslint from 'eslint';
import { basename } from 'path';
const linter = new eslint.CLIEngine({ configFile: './eslintrc.js' });
const unique = arr => Array.from(new Set(arr));
test('should pass files that have no issues', t => {
const results = linter.executeOnFiles(['test-helpers/pass/**/*.js']);
const errorMessages = () =>
results.results.map(r => unique(r.messages.map(rule => rule.ruleId)));
t.is(
results.errorCount,
0,
`Unexpectedly failed with these errors: ${errorMessages()}`
);
});
test('should fail on files with issues', t => {
const { results } = linter.executeOnFiles(['test-helpers/fail/**/*.js']);
results.forEach(({ filePath, messages, errorCount }) => {
t.true(errorCount > 0);
const testedRule = basename(filePath, '.js');
const rules = messages.map(rule => rule.ruleId.replace(/\//g, '_'));
t.assert(
rules.includes(testedRule),
`Expected to find ${testedRule} in [${rules.join(', ')}]`
);
});
});