Skip to content

Commit

Permalink
Generalize TocGrouping.test.ts for future Qiskit versions (Qiskit#1383)
Browse files Browse the repository at this point in the history
Closes Qiskit#1341.
  • Loading branch information
Eric-Arellano authored May 15, 2024
1 parent 8e505a9 commit a78844f
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions scripts/lib/api/TocGrouping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -121,13 +121,38 @@ async function getTocModuleGroups(fp: string): Promise<ModuleGroup[]> {
return result;
}

test("Qiskit ToC mirrors index page sections", async () => {
validateTopLevelModuleAssumptions();
async function checkFolder(dirName: string): Promise<void> {
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}`);
}
});
});

0 comments on commit a78844f

Please sign in to comment.