From 73b1e9ce5cc52824b1577bca418f6935eacab67b Mon Sep 17 00:00:00 2001 From: Steve Landey Date: Wed, 4 Sep 2024 13:28:15 -0700 Subject: [PATCH] Tests work better but not perfectly (spinners persist) --- {src/e2e/docs => examples/e2e}/djockey.yaml | 0 {src/e2e/docs => examples/e2e}/out/.gitignore | 0 {src/e2e/docs => examples/e2e}/src/index.djot | 0 .../e2e}/src/subdirectory/image.png | Bin .../e2e}/src/subdirectory/index.djot | 0 src/{e2e => }/endToEnd.test.ts | 22 ++++++++++++------ src/plugins/autoTitlePlugin.test.ts | 12 ++++++---- src/plugins/tableOfContentsPlugin.test.ts | 6 +++-- src/utils/logUtils.ts | 1 + 9 files changed, 28 insertions(+), 13 deletions(-) rename {src/e2e/docs => examples/e2e}/djockey.yaml (100%) rename {src/e2e/docs => examples/e2e}/out/.gitignore (100%) rename {src/e2e/docs => examples/e2e}/src/index.djot (100%) rename {src/e2e/docs => examples/e2e}/src/subdirectory/image.png (100%) rename {src/e2e/docs => examples/e2e}/src/subdirectory/index.djot (100%) rename src/{e2e => }/endToEnd.test.ts (60%) diff --git a/src/e2e/docs/djockey.yaml b/examples/e2e/djockey.yaml similarity index 100% rename from src/e2e/docs/djockey.yaml rename to examples/e2e/djockey.yaml diff --git a/src/e2e/docs/out/.gitignore b/examples/e2e/out/.gitignore similarity index 100% rename from src/e2e/docs/out/.gitignore rename to examples/e2e/out/.gitignore diff --git a/src/e2e/docs/src/index.djot b/examples/e2e/src/index.djot similarity index 100% rename from src/e2e/docs/src/index.djot rename to examples/e2e/src/index.djot diff --git a/src/e2e/docs/src/subdirectory/image.png b/examples/e2e/src/subdirectory/image.png similarity index 100% rename from src/e2e/docs/src/subdirectory/image.png rename to examples/e2e/src/subdirectory/image.png diff --git a/src/e2e/docs/src/subdirectory/index.djot b/examples/e2e/src/subdirectory/index.djot similarity index 100% rename from src/e2e/docs/src/subdirectory/index.djot rename to examples/e2e/src/subdirectory/index.djot diff --git a/src/e2e/endToEnd.test.ts b/src/endToEnd.test.ts similarity index 60% rename from src/e2e/endToEnd.test.ts rename to src/endToEnd.test.ts index 7606ecd..3aeed7e 100644 --- a/src/e2e/endToEnd.test.ts +++ b/src/endToEnd.test.ts @@ -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); @@ -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(); }); diff --git a/src/plugins/autoTitlePlugin.test.ts b/src/plugins/autoTitlePlugin.test.ts index 641b3e4..db45260 100644 --- a/src/plugins/autoTitlePlugin.test.ts +++ b/src/plugins/autoTitlePlugin.test.ts @@ -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( @@ -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( @@ -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"); }); diff --git a/src/plugins/tableOfContentsPlugin.test.ts b/src/plugins/tableOfContentsPlugin.test.ts index 9eeb563..e5ad170 100644 --- a/src/plugins/tableOfContentsPlugin.test.ts +++ b/src/plugins/tableOfContentsPlugin.test.ts @@ -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(`