-
Notifications
You must be signed in to change notification settings - Fork 67k
Expand file tree
/
Copy pathrendering.ts
More file actions
85 lines (76 loc) · 3.07 KB
/
rendering.ts
File metadata and controls
85 lines (76 loc) · 3.07 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
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
import { readFileSync } from 'fs'
import { load } from 'cheerio'
import { describe, expect, test, vi } from 'vitest'
import { loadPages } from '@/frame/lib/page-data'
import { get } from '@/tests/helpers/e2etest'
// Type definitions for page objects
type Page = {
autogenerated?: string
fullPath: string
permalinks: Array<{ href: string }>
versions: {
feature?: string | string[]
[key: string]: string | string[] | undefined
}
}
// Get a list of the autogenerated pages
const pageList: Page[] = await loadPages(undefined, ['en'])
describe('autogenerated docs render', () => {
vi.setConfig({ testTimeout: 3 * 60 * 1000 })
const autogeneratedPages = pageList.filter((page: Page) => page.autogenerated)
test('all automated pages', async () => {
// Each page should render with 200 OK. Also, check for duplicate
// heading IDs on each page.
const errors = (
await Promise.all(
autogeneratedPages.map(async (page: Page) => {
const url = page.permalinks[0].href
// Some autogenerated pages can be very slow and might fail.
// So we allow a few retries to avoid false positives.
const res = await get(url, { retries: 3 })
if (res.statusCode !== 200) {
return `${res.statusCode} status error on ${url}`
}
// Using `xmlMode: true` is marginally faster
const $ = load(res.body, { xmlMode: true })
const headingIDs = $('body')
.find('h2, h3, h4, h5, h6')
.map((_, el) => $(el).attr('id'))
.get()
.sort()
const dupes = headingIDs.filter(
(item: string, index: number) => headingIDs.indexOf(item) !== index,
)
if (dupes.length) {
return `In ${url}, the following duplicate heading IDs were found: ${dupes.join(', ')}`
}
}),
)
).filter(Boolean) as string[]
expect(errors.length, errors.join('\n')).toBe(0)
})
const codeqlCliPath: string = JSON.parse(
readFileSync('src/codeql-cli/lib/config.json', 'utf-8'),
).targetDirectory
const restPath: string = JSON.parse(
readFileSync('src/rest/lib/config.json', 'utf-8'),
).targetDirectory
const ghappsPath: string = JSON.parse(
readFileSync('src/github-apps/lib/config.json', 'utf-8'),
).targetDirectory
// Right now only the rest and codeqlcli pages get their frontmatter updated automatically.
// The apps pages do not get their frontmatter auto-updated since they apply to all versions and they are
// single pages. The apps pages are also nested inside of the rest pages. So we want to filter out only
// rest pages and the codeql cli pages for this test.
const filesWithAutoUpdatedVersions = autogeneratedPages.filter(
(page: Page) =>
(!page.fullPath.startsWith(ghappsPath) && page.fullPath.startsWith(restPath)) ||
page.fullPath.startsWith(codeqlCliPath),
)
test.each(filesWithAutoUpdatedVersions)(
'autogenerated page $fullPath does not use feature based versioning',
(page: Page) => {
expect(page.versions.feature).toBe(undefined)
},
)
})