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 { readFileSync } from 'fs'
|
||||||
|
|
||||||
|
import cheerio from 'cheerio'
|
||||||
|
import { jest, test } from '@jest/globals'
|
||||||
|
|
||||||
import { loadPages } from '../../../lib/page-data.js'
|
import { loadPages } from '../../../lib/page-data.js'
|
||||||
import { get } from '../../../tests/helpers/e2etest.js'
|
import { get } from '../../../tests/helpers/e2etest.js'
|
||||||
|
|
||||||
@@ -12,22 +14,34 @@ describe('autogenerated docs render', () => {
|
|||||||
|
|
||||||
const autogeneratedPages = pageList.filter((page) => page.autogenerated)
|
const autogeneratedPages = pageList.filter((page) => page.autogenerated)
|
||||||
|
|
||||||
test('all automated pages return a 200 success code', async () => {
|
test('all automated pages', async () => {
|
||||||
expect.assertions(autogeneratedPages.length)
|
// Each page should render with 200 OK. Also, check for duplicate
|
||||||
|
// heading IDs on each page.
|
||||||
const statusCodes = await Promise.all(
|
const errors = (
|
||||||
autogeneratedPages.map(async (page) => {
|
await Promise.all(
|
||||||
const url = page.permalinks[0].href
|
autogeneratedPages.map(async (page) => {
|
||||||
// Some autogenerated pages can be very slow and might fail.
|
const url = page.permalinks[0].href
|
||||||
// So we allow a few retries to avoid false positives.
|
// Some autogenerated pages can be very slow and might fail.
|
||||||
const res = await get(url, { retries: 3 })
|
// So we allow a few retries to avoid false positives.
|
||||||
return [url, res.statusCode]
|
const res = await get(url, { retries: 3 })
|
||||||
}),
|
if (res.statusCode !== 200) {
|
||||||
)
|
return `${res.statusCode} status error on ${url}`
|
||||||
|
}
|
||||||
for (const [url, status] of statusCodes) {
|
// Using `xmlMode: true` is marginally faster
|
||||||
expect(status, url).toBe(200)
|
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(
|
const codeqlCliPath = JSON.parse(
|
||||||
|
|||||||
Reference in New Issue
Block a user