forked from testing-library/eslint-plugin-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
80 lines (67 loc) · 2.07 KB
/
index.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
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
import { existsSync } from 'fs';
import { resolve } from 'path';
import plugin from '../lib';
const numberOfRules = 27;
const ruleNames = Object.keys(plugin.rules);
// eslint-disable-next-line jest/expect-expect
it('should have a corresponding doc for each rule', () => {
ruleNames.forEach((rule) => {
const docPath = resolve(__dirname, '../docs/rules', `${rule}.md`);
if (!existsSync(docPath)) {
throw new Error(
`Could not find documentation file for rule "${rule}" in path "${docPath}"`
);
}
});
});
// eslint-disable-next-line jest/expect-expect
it('should have a corresponding test for each rule', () => {
ruleNames.forEach((rule) => {
const testPath = resolve(__dirname, './lib/rules/', `${rule}.test.ts`);
if (!existsSync(testPath)) {
throw new Error(
`Could not find test file for rule "${rule}" in path "${testPath}"`
);
}
});
});
// eslint-disable-next-line jest/expect-expect
it('should have the correct amount of rules', () => {
const { length } = ruleNames;
if (length !== numberOfRules) {
throw new Error(
`There should be exactly ${numberOfRules} rules, but there are ${length}. If you've added a new rule, please update this number.`
);
}
});
it('should export configs that refer to actual rules', () => {
const allConfigs = plugin.configs;
expect(Object.keys(allConfigs)).toEqual([
'dom',
'angular',
'react',
'vue',
'svelte',
'marko',
'flat/dom',
'flat/angular',
'flat/react',
'flat/vue',
'flat/svelte',
'flat/marko',
]);
const allConfigRules = Object.values(allConfigs)
.map((config) => Object.keys(config.rules))
.reduce((previousValue, currentValue) => [
...previousValue,
...currentValue,
]);
allConfigRules.forEach((rule) => {
const ruleNamePrefix = 'testing-library/';
const ruleName = rule.slice(ruleNamePrefix.length);
expect(rule.startsWith(ruleNamePrefix)).toBe(true);
expect(ruleNames).toContain(ruleName);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports
expect(() => require(`../lib/rules/${ruleName}`)).not.toThrow();
});
});