From a78844fea01181c820ed4e14acc04434bd32a3ea Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Wed, 15 May 2024 07:24:45 -0400 Subject: [PATCH] Generalize TocGrouping.test.ts for future Qiskit versions (#1383) Closes https://github.com/Qiskit/documentation/issues/1341. --- scripts/lib/api/TocGrouping.test.ts | 37 ++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/scripts/lib/api/TocGrouping.test.ts b/scripts/lib/api/TocGrouping.test.ts index 6c1dd25a902..b445b0d28fb 100644 --- a/scripts/lib/api/TocGrouping.test.ts +++ b/scripts/lib/api/TocGrouping.test.ts @@ -10,9 +10,9 @@ // copyright notice, and modified files need to carry a notice indicating // that they have been altered from the originals. -import { readFile } from "fs/promises"; +import { readFile, readdir } from "fs/promises"; -import { expect, test } from "@jest/globals"; +import { expect, describe, test } from "@jest/globals"; import { QISKIT_TOC_GROUPING } from "./TocGrouping"; import type { TocEntry } from "./generateToc"; @@ -121,13 +121,38 @@ async function getTocModuleGroups(fp: string): Promise { return result; } -test("Qiskit ToC mirrors index page sections", async () => { - validateTopLevelModuleAssumptions(); +async function checkFolder(dirName: string): Promise { const indexModuleGroups = await getIndexModuleGroups( - "docs/api/qiskit/dev/index.mdx", + `docs/api/qiskit${dirName}/index.mdx`, ); const tocModuleGroups = await getTocModuleGroups( - "docs/api/qiskit/dev/_toc.json", + `docs/api/qiskit${dirName}/_toc.json`, ); expect(indexModuleGroups).toEqual(tocModuleGroups); +} + +describe("Qiskit ToC mirrors index page sections", () => { + test("validate assumptions", () => { + validateTopLevelModuleAssumptions(); + }); + + test("dev", async () => { + await checkFolder("/dev"); + }); + + test.failing("latest", async () => { + await checkFolder(""); + }); + + test("historical releases (1.1+)", async () => { + const folders = ( + await readdir("docs/api/qiskit", { withFileTypes: true }) + ).filter( + (file) => + file.isDirectory() && file.name.match(/[0-9].*/) && +file.name >= 1.1, + ); + for (const folder of folders) { + await checkFolder(`/${folder.name}`); + } + }); });