-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
documentation.spec.ts
103 lines (85 loc) · 3.06 KB
/
documentation.spec.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import fs from 'fs-extra';
import { glob } from 'glob';
import { getOptions, isTopLevelOnlyOption } from '../lib/config/options';
import { regEx } from '../lib/util/regex';
const options = getOptions();
const markdownGlob = '{docs,lib}/**/*.md';
describe('documentation', () => {
it('has no invalid links', async () => {
const markdownFiles = await glob(markdownGlob);
await Promise.all(
markdownFiles.map(async (markdownFile) => {
const markdownText = await fs.readFile(markdownFile, 'utf8');
expect(markdownText).not.toMatch(regEx(/\.md\/#/));
}),
);
});
describe('website-documentation', () => {
describe('configuration-options', () => {
const doc = fs.readFileSync(
'docs/usage/configuration-options.md',
'utf8',
);
const headers = doc
.match(/\n## (.*?)\n/g)
?.map((match) => match.substring(4, match.length - 1));
const expectedOptions = options
.filter((option) => !option.globalOnly)
.filter((option) => !option.parents || isTopLevelOnlyOption(option))
.filter((option) => !option.autogenerated)
.map((option) => option.name)
.sort();
it('has doc headers sorted alphabetically', () => {
expect(headers).toEqual([...headers!].sort());
});
it('has headers for every required option', () => {
expect(headers).toEqual(expectedOptions);
});
const subHeaders = doc
.match(/\n### (.*?)\n/g)
?.map((match) => match.substring(5, match.length - 1));
subHeaders!.sort();
const expectedSubOptions = options
.filter((option) => option.stage !== 'global')
.filter((option) => !option.globalOnly)
.filter((option) => option.parents && !isTopLevelOnlyOption(option))
.map((option) => option.name)
.sort();
expectedSubOptions.sort();
it('has headers for every required sub-option', () => {
expect(subHeaders).toEqual(expectedSubOptions);
});
});
describe('self-hosted-configuration', () => {
const doc = fs.readFileSync(
'docs/usage/self-hosted-configuration.md',
'utf8',
);
const headers = doc
.match(/\n## (.*?)\n/g)
?.map((match) => match.substring(4, match.length - 1));
const expectedOptions = options
.filter((option) => !!option.globalOnly)
.map((option) => option.name)
.sort();
it('has headers sorted alphabetically', () => {
expect(headers).toEqual([...headers!].sort());
});
it('has headers for every required option', () => {
expect(headers).toEqual(expectedOptions);
});
});
describe('self-hosted-experimental', () => {
const doc = fs.readFileSync(
'docs/usage/self-hosted-experimental.md',
'utf8',
);
const headers = doc
.match(/\n## (.*?)\n/g)
?.map((match) => match.substring(4, match.length - 1));
it('has headers sorted alphabetically', () => {
expect(headers).toEqual([...headers!].sort());
});
});
});
});