Skip to content

Commit

Permalink
Tests work better but not perfectly (spinners persist)
Browse files Browse the repository at this point in the history
  • Loading branch information
irskep committed Sep 4, 2024
1 parent add10a8 commit 73b1e9c
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 13 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
22 changes: 15 additions & 7 deletions src/e2e/endToEnd.test.ts → src/endToEnd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import path, { dirname } from "path";
import { fileURLToPath } from "url";

import fastGlob from "fast-glob";
import { executeConfig } from "../engine/executeConfig.js";
import { resolveConfigFromDirectory } from "../config.js";
import { LogCollector } from "../utils/logUtils.js";
import { executeConfig } from "./engine/executeConfig.js";
import { resolveConfigFromDirectory } from "./config.js";
import { LogCollector } from "./utils/logUtils.js";

function rmrf(parentDir: string) {
console.log("rm -rf", parentDir);
Expand All @@ -21,16 +21,24 @@ function rmrf(parentDir: string) {
}

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const inputRoot = path.join(__dirname, "docs");
const outputRoot = path.join(__dirname, "out");
const e2eDataRoot = path.resolve(
path.join(dirname(__filename), "..", "examples", "e2e")
);
const inputRoot = path.join(e2eDataRoot);
const outputRoot = path.join(inputRoot, "out");

beforeEach(() => {
rmrf(outputRoot);
});

test("HTML rendering", async () => {
console.log("Tests are looking in", inputRoot);
const config = resolveConfigFromDirectory(inputRoot, true)!;
const logCollector = new LogCollector("E2E", { silent: true });
expect(config).toBeTruthy();
const logCollector = new LogCollector("E2E", {
silent: true,
shouldStart: false,
});
await executeConfig(config, ["html"], logCollector);
expect(logCollector.hasWarningsOrErrors).toBeFalsy();
});
12 changes: 8 additions & 4 deletions src/plugins/autoTitlePlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DocSet } from "../engine/docset.js";
import { getConfigDefaults } from "../config.js";
import { LogCollector } from "../utils/logUtils.js";

test("Title is set to first heading by default", () => {
test("Title is set to first heading by default", async () => {
const doc: DjockeyDoc = {
docs: {
content: parse(
Expand Down Expand Up @@ -40,12 +40,14 @@ test("Title is set to first heading by default", () => {
url_root: "URL_ROOT",
};
const docSet = new DocSet(config, [new AutoTitlePlugin()], [doc]);
docSet.runPasses(new LogCollector("", { shouldStart: false }));
await docSet.runPasses(
new LogCollector("", { shouldStart: false, silent: true })
);

expect(doc.title).toEqual("Heading 1");
});

test("Title is set to frontMatter.title if present", () => {
test("Title is set to frontMatter.title if present", async () => {
const doc: DjockeyDoc = {
docs: {
content: parse(
Expand Down Expand Up @@ -80,7 +82,9 @@ test("Title is set to frontMatter.title if present", () => {
url_root: "URL_ROOT",
};
const docSet = new DocSet(config, [new AutoTitlePlugin()], [doc]);
docSet.runPasses(new LogCollector("", { shouldStart: false }));
await docSet.runPasses(
new LogCollector("", { shouldStart: false, silent: true })
);

expect(doc.title).toEqual("Custom title");
});
6 changes: 4 additions & 2 deletions src/plugins/tableOfContentsPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ test("Works end-to-end with LinkRewritingPlugin", async () => {
[new TableOfContentsPlugin(), new LinkRewritingPlugin(config)],
[doc]
);
await docSet.runPasses(new LogCollector("", { shouldStart: false }));
await docSet.runPasses(
new LogCollector("", { shouldStart: false, silent: true })
);
const htmlCopy = docSet.makeRenderableCopy(
new HTMLRenderer({ relativeLinks: true }),
new LogCollector("", { shouldStart: false })
new LogCollector("", { shouldStart: false, silent: true })
)[0];
const html = renderHTML(htmlCopy.docs.toc);
expect(html).toEqual(`<ul>
Expand Down
1 change: 1 addition & 0 deletions src/utils/logUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class LogCollector {
private loader?: ReturnType<typeof print.spin>;
private silent = false;
private parent?: LogCollector;
private children = new Array<LogCollector>();

constructor(
public label: string,
Expand Down

0 comments on commit 73b1e9c

Please sign in to comment.