forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoc-links.js
More file actions
46 lines (38 loc) · 1.38 KB
/
toc-links.js
File metadata and controls
46 lines (38 loc) · 1.38 KB
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
const { loadPages } = require('../../lib/pages')
const renderContent = require('../../lib/render-content')
const allVersions = Object.keys(require('../../lib/all-versions'))
describe('toc links', () => {
jest.setTimeout(3 * 60 * 1000)
test('every toc link works without redirects', async () => {
const pages = await loadPages()
const englishIndexPages = pages
.filter(page => page.languageCode === 'en' && page.relativePath.endsWith('index.md'))
const issues = []
for (const pageVersion of allVersions) {
for (const page of englishIndexPages) {
// skip page if it doesn't have a permalink for the current product version
if (!page.permalinks.some(permalink => permalink.pageVersion === pageVersion)) continue
// build fake context object for rendering the page
const context = {
page,
pages,
redirects: {},
currentLanguage: 'en',
currentVersion: pageVersion
}
// ensure all toc pages can render
try {
await renderContent(page.markdown, context)
} catch (err) {
issues.push({
'TOC path': page.relativePath,
error: err.message,
pageVersion
})
}
}
}
const message = 'broken link in a TOC: ' + JSON.stringify(issues, null, 2)
expect(issues.length, message).toBe(0)
})
})