-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.test.ts
51 lines (39 loc) · 1.7 KB
/
eslint.test.ts
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
import test from 'ava';
import eslint from 'eslint';
import { getBaseFileName, getRuleIDs } from './test-helpers/lib';
const linter = new eslint.CLIEngine({ configFile: './.eslintrc.js' });
test('should pass files that have no issues', t => {
const results = linter.executeOnFiles(['test-helpers/pass/**/*']);
const errorMessages = () => getRuleIDs(results).join(', ');
t.is(
results.errorCount + results.warningCount,
0,
`Unexpectedly failed with these errors: ${errorMessages()}`
);
});
test('should error on files with issues', t => {
const { results } = linter.executeOnFiles(['test-helpers/error/**/*']);
results.forEach(({ filePath, messages, errorCount }) => {
t.true(errorCount > 0, `Expected errors in ${filePath}, but found none.`);
const failedRules = messages.map(rule => rule.ruleId);
const ruleBaseName = getBaseFileName(filePath).replace(/_/g, '/');
t.assert(
failedRules.includes(ruleBaseName) ||
failedRules.includes(`@typescript-eslint/${ruleBaseName}`),
`Expected to find ${ruleBaseName} in [${failedRules.join(', ')}]`
);
});
});
test('should warn on files with warnings', t => {
const { results } = linter.executeOnFiles(['test-helpers/warn/**/*']);
results.forEach(({ filePath, messages, warningCount }) => {
t.true(warningCount > 0, `Expected errors in ${filePath}, but found none.`);
const failedRules = messages.map(rule => rule.ruleId);
const ruleBaseName = getBaseFileName(filePath).replace(/_/g, '/');
t.assert(
failedRules.includes(ruleBaseName) ||
failedRules.includes(`@typescript-eslint/${ruleBaseName}`),
`Expected to find ${ruleBaseName} in [${failedRules.join(', ')}]`
);
});
});