forked from effector/eslint-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocs.test.js
84 lines (68 loc) · 2.7 KB
/
docs.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const { readFile, readdir } = require("fs/promises");
const { join } = require("path");
const plugin = require("./index");
describe("docs", () => {
test("any rule should have valid doc.md", async () => {
await Promise.all([
Object.entries(plugin.rules).map(async ([ruleName]) => {
const ruleFiles = await readdir(join(__dirname, "rules", ruleName));
// File exists
expect(ruleFiles).toContain(`${ruleName}.md`);
const ruleDocFile = await readFile(
join(__dirname, "rules", ruleName, `${ruleName}.md`),
"utf8"
);
// File has valid title
expect(ruleDocFile).toContain(`effector/${ruleName}`);
}),
]);
});
test("any rule should have like in main README.md", async () => {
const readmeContent = await readFile(join(__dirname, "README.md"), "utf8");
await Promise.all([
Object.entries(plugin.rules).map(async ([ruleName]) => {
// Link exists
expect(readmeContent).toContain(
`- [effector/${ruleName}](rules/${ruleName}/${ruleName}.md)`
);
}),
]);
});
test("any config should be presented in main README.md", async () => {
const readmeContent = await readFile(join(__dirname, "README.md"), "utf8");
await Promise.all([
Object.entries(plugin.configs).map(async ([configName]) => {
expect(readmeContent).toContain(`#### plugin:effector/${configName}`);
}),
]);
});
test("any config should have list of rules in main README.md", async () => {
const readmeContent = await readFile(join(__dirname, "README.md"), "utf8");
await Promise.all([
Object.entries(plugin.configs).map(async ([configName, config]) => {
const [_, readmeContentAfterConfigDocSectionStart] =
readmeContent.split(`#### plugin:effector/${configName}`);
const [readmeContentConfigDocSection] =
readmeContentAfterConfigDocSectionStart.split("###");
const includedRuleNames = Object.keys(config.rules).map((fullName) =>
fullName.replace("effector/", "")
);
const excludedRules = Object.keys(plugin.rules).filter(
(rule) => !includedRuleNames.includes(rule)
);
// Has links to included rules
for (const ruleName of includedRuleNames) {
expect(readmeContentConfigDocSection).toContain(
`- [effector/${ruleName}](rules/${ruleName}/${ruleName}.md)`
);
}
// Does not have links to excluded rules
for (const ruleName of excludedRules) {
expect(readmeContentConfigDocSection).not.toContain(
`- [effector/${ruleName}](rules/${ruleName}/${ruleName}.md)`
);
}
}),
]);
});
});