1
0
mirror of synced 2025-12-19 18:10:59 -05:00

ensure all autogenerated pages render (#36474)

Co-authored-by: Peter Bengtsson <mail@peterbe.com>
Co-authored-by: Peter Bengtsson <peterbe@github.com>
This commit is contained in:
Rachael Sewell
2023-04-20 11:53:33 -07:00
committed by GitHub
parent 5877af3e79
commit 74c1fec1b3
4 changed files with 17 additions and 32 deletions

View File

@@ -84,7 +84,6 @@ children:
- /teams
- /users
- /webhooks
autogenerated: rest
---

View File

@@ -1,45 +1,30 @@
import { jest, test } from '@jest/globals'
import { readdirSync, readFileSync } from 'fs'
import path from 'path'
import { loadPages } from '../../../lib/page-data.js'
import { get } from '../../../tests/helpers/e2etest.js'
import { REST_DATA_DIR, REST_SCHEMA_FILENAME } from '../../rest/lib/index.js'
// TODO: Change to test every automated page, not just rest
describe('REST references docs', () => {
describe('autogenerated docs render', () => {
jest.setTimeout(3 * 60 * 1000)
test('all category and subcategory REST pages render for free-pro-team', async () => {
// This currently just grabs the 'free-pro-team' schema, but ideally, we'd
// get a list of all categories across all versions.
const freeProTeamVersion = readdirSync(REST_DATA_DIR)
.filter((file) => file.startsWith('fpt'))
.shift()
const freeProTeamSchema = JSON.parse(
readFileSync(path.join(REST_DATA_DIR, freeProTeamVersion, REST_SCHEMA_FILENAME), 'utf8')
)
test('all automated pages return a 200 success code', async () => {
// Get a list of the autogenerated pages
const pageList = await loadPages(undefined, ['en'])
const autogeneratedPages = pageList.filter((page) => page.autogenerated)
const restCategories = Object.entries(freeProTeamSchema)
.map(([key, subCategory]) => {
const subCategoryKeys = Object.keys(subCategory)
if (subCategoryKeys.length === 1) {
return key
} else {
return subCategoryKeys.map((elem) => `${key}/${elem}`)
}
})
.flat()
expect.assertions(autogeneratedPages.length)
const statusCodes = await Promise.all(
restCategories.map(async (page) => {
const url = `/en/rest/${page}`
const res = await get(url)
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)
}
expect.assertions(restCategories.length)
})
})

View File

@@ -5,8 +5,8 @@ import { describe } from '@jest/globals'
import walk from 'walk-sync'
import { isPlainObject, difference } from 'lodash-es'
import { isApiVersioned, allVersions } from '../../lib/all-versions.js'
import getRest from '../../src/rest/lib/index.js'
import { isApiVersioned, allVersions } from '../../../lib/all-versions.js'
import getRest from '../lib/index.js'
const schemasPath = 'src/rest/data'

View File

@@ -11,6 +11,7 @@ export async function get(
followAllRedirects: false,
headers: {},
responseType: undefined,
retries: 0,
}
) {
const method = opts.method || 'get'
@@ -21,7 +22,7 @@ export async function get(
{
body: opts.body,
headers: opts.headers,
retry: { limit: 0 },
retry: { limit: opts.retries || 0 },
throwHttpErrors: false,
followRedirect: opts.followAllRedirects || opts.followRedirects,
responseType: opts.responseType,