Check for duplicate IDs in all autogenerated pages (#36664)
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
import { jest, test } from '@jest/globals'
|
||||
|
||||
import { getDOMCached as getDOM } from '../../../tests/helpers/e2etest.js'
|
||||
|
||||
describe('automated page heading accessibility', () => {
|
||||
jest.setTimeout(3 * 60 * 1000)
|
||||
|
||||
test('rest pages do not render any headings with duplicate text', async () => {
|
||||
const $ = await getDOM('/en/rest/actions/artifacts')
|
||||
const headingText = $('body')
|
||||
.find('h2, h3, h4, h5, h6')
|
||||
.map((i, el) => $(el).text())
|
||||
.get()
|
||||
.sort()
|
||||
|
||||
const dupes = headingText.filter((item, index) => headingText.indexOf(item) !== index)
|
||||
|
||||
const message = `The following duplicate heading texts were found: ${dupes.join(', ')}`
|
||||
expect(dupes.length, message).toBe(0)
|
||||
})
|
||||
|
||||
test('rest pages do not render any headings with duplicate ids', async () => {
|
||||
const $ = await getDOM('/en/rest/actions/artifacts')
|
||||
const headingIDs = $('body')
|
||||
.find('h2, h3, h4, h5, h6')
|
||||
.map((i, el) => $(el).attr('id'))
|
||||
.get()
|
||||
.sort()
|
||||
|
||||
const dupes = headingIDs.filter((item, index) => headingIDs.indexOf(item) !== index)
|
||||
|
||||
const message = `The following duplicate heading IDs were found: ${dupes.join(', ')}`
|
||||
expect(dupes.length, message).toBe(0)
|
||||
})
|
||||
|
||||
test('webhook pages do not render any headings with duplicate text', async () => {
|
||||
const $ = await getDOM('/en/webhooks-and-events/webhooks/webhook-events-and-payloads')
|
||||
const headingText = $('body')
|
||||
.find('h2, h3, h4, h5, h6')
|
||||
.map((i, el) => $(el).text())
|
||||
.get()
|
||||
.sort()
|
||||
|
||||
const dupes = headingText.filter((item, index) => headingText.indexOf(item) !== index)
|
||||
|
||||
const message = `The following duplicate heading texts were found: ${dupes.join(', ')}`
|
||||
expect(dupes.length, message).toBe(0)
|
||||
})
|
||||
|
||||
test('webhook pages do not render any headings with duplicate ids', async () => {
|
||||
const $ = await getDOM('/en/webhooks-and-events/webhooks/webhook-events-and-payloads')
|
||||
const headingIDs = $('body')
|
||||
.find('h2, h3, h4, h5, h6')
|
||||
.map((i, el) => $(el).attr('id'))
|
||||
.get()
|
||||
.sort()
|
||||
|
||||
const dupes = headingIDs.filter((item, index) => headingIDs.indexOf(item) !== index)
|
||||
|
||||
const message = `The following duplicate heading IDs were found: ${dupes.join(', ')}`
|
||||
expect(dupes.length, message).toBe(0)
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,8 @@
|
||||
import { jest, test } from '@jest/globals'
|
||||
import { readFileSync } from 'fs'
|
||||
|
||||
import cheerio from 'cheerio'
|
||||
import { jest, test } from '@jest/globals'
|
||||
|
||||
import { loadPages } from '../../../lib/page-data.js'
|
||||
import { get } from '../../../tests/helpers/e2etest.js'
|
||||
|
||||
@@ -12,22 +14,34 @@ describe('autogenerated docs render', () => {
|
||||
|
||||
const autogeneratedPages = pageList.filter((page) => page.autogenerated)
|
||||
|
||||
test('all automated pages return a 200 success code', async () => {
|
||||
expect.assertions(autogeneratedPages.length)
|
||||
|
||||
const statusCodes = await Promise.all(
|
||||
autogeneratedPages.map(async (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 })
|
||||
return [url, res.statusCode]
|
||||
}),
|
||||
)
|
||||
|
||||
for (const [url, status] of statusCodes) {
|
||||
expect(status, url).toBe(200)
|
||||
}
|
||||
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) => {
|
||||
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 $ = cheerio.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, index) => headingIDs.indexOf(item) !== index)
|
||||
if (dupes.length) {
|
||||
return `In ${url}, the following duplicate heading IDs were found: ${dupes.join(', ')}`
|
||||
}
|
||||
}),
|
||||
)
|
||||
).filter(Boolean)
|
||||
expect(errors.length, errors.join('\n')).toBe(0)
|
||||
})
|
||||
|
||||
const codeqlCliPath = JSON.parse(
|
||||
|
||||
Reference in New Issue
Block a user