AbdulElahGwaith's picture
Upload folder using huggingface_hub
88df9e4 verified
import { describe, expect, test, vi } from 'vitest'
import { loadPageMap, loadPages } from '@/frame/lib/page-data'
import { renderContent } from '@/content-render/index'
import { allVersions } from '@/versions/lib/all-versions'
import type { Permalink } from '@/types'
describe('toc links', () => {
vi.setConfig({ testTimeout: 3 * 60 * 1000 })
test('every toc link works without redirects', async () => {
const pageList = await loadPages()
const englishIndexPages = pageList.filter(
(page) => page.languageCode === 'en' && page.relativePath.endsWith('index.md'),
)
const pages = await loadPageMap(pageList)
const issues = []
for (const pageVersion of Object.keys(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) => permalink.pageVersion === pageVersion))
continue
// build fake context object for rendering the page
const context = {
page,
pages,
redirects: {},
currentLanguage: 'en',
currentVersion: pageVersion,
currentVersionObj: allVersions[pageVersion],
}
// ensure all toc pages can render
try {
await renderContent(page.markdown, context)
} catch (err) {
issues.push({
'TOC path': page.relativePath,
error: err instanceof Error ? err.message : String(err),
pageVersion,
})
}
}
}
const message = `broken link in a TOC: ${JSON.stringify(issues, null, 2)}`
expect(issues.length, message).toBe(0)
})
})