From 73358a363d9d4bc8748cb9925616a7a3b47b699a Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Thu, 14 May 2026 08:11:32 -0500 Subject: [PATCH] chore: change inputs to use fixture folders --- .../input/[name]/_paths.blot | 5 + .../input/[name]/index.ts.blot | 9 ++ .../input/[name]/static.txt | 1 + .../fixtures/dynamic-files/input/[path].blot | 13 +++ .../skip-existing/input/test.txt.blot | 1 + .../fixtures/skip-existing/output/test.txt | 1 + .../fixtures/static/input/test.json.blot | 7 ++ packages/generator/tests/index.spec.ts | 99 +++++-------------- 8 files changed, 64 insertions(+), 72 deletions(-) create mode 100644 packages/generator/tests/fixtures/dynamic-directories/input/[name]/_paths.blot create mode 100644 packages/generator/tests/fixtures/dynamic-directories/input/[name]/index.ts.blot create mode 100644 packages/generator/tests/fixtures/dynamic-directories/input/[name]/static.txt create mode 100644 packages/generator/tests/fixtures/dynamic-files/input/[path].blot create mode 100644 packages/generator/tests/fixtures/skip-existing/input/test.txt.blot create mode 100644 packages/generator/tests/fixtures/skip-existing/output/test.txt create mode 100644 packages/generator/tests/fixtures/static/input/test.json.blot diff --git a/packages/generator/tests/fixtures/dynamic-directories/input/[name]/_paths.blot b/packages/generator/tests/fixtures/dynamic-directories/input/[name]/_paths.blot new file mode 100644 index 0000000..5e6a034 --- /dev/null +++ b/packages/generator/tests/fixtures/dynamic-directories/input/[name]/_paths.blot @@ -0,0 +1,5 @@ + +export function getPaths() { + return [{ name: "one" }, { name: "two" }]; +} + diff --git a/packages/generator/tests/fixtures/dynamic-directories/input/[name]/index.ts.blot b/packages/generator/tests/fixtures/dynamic-directories/input/[name]/index.ts.blot new file mode 100644 index 0000000..9c8928b --- /dev/null +++ b/packages/generator/tests/fixtures/dynamic-directories/input/[name]/index.ts.blot @@ -0,0 +1,9 @@ + +import { useParams } from "tempblot"; + +const { name } = useParams<{ name: string }>(); + + + +export const name = "<>"; + diff --git a/packages/generator/tests/fixtures/dynamic-directories/input/[name]/static.txt b/packages/generator/tests/fixtures/dynamic-directories/input/[name]/static.txt new file mode 100644 index 0000000..7c29dd8 --- /dev/null +++ b/packages/generator/tests/fixtures/dynamic-directories/input/[name]/static.txt @@ -0,0 +1 @@ +copied diff --git a/packages/generator/tests/fixtures/dynamic-files/input/[path].blot b/packages/generator/tests/fixtures/dynamic-files/input/[path].blot new file mode 100644 index 0000000..758ac39 --- /dev/null +++ b/packages/generator/tests/fixtures/dynamic-files/input/[path].blot @@ -0,0 +1,13 @@ + +import { useParams } from "tempblot"; + +export function getPaths() { + return [{ path: "one.js", val: 1 }, { path: "two.js", val: 2 }]; +} + +const { val } = useParams<{ path: string; val: number }>(); + + + +console.log(<>); + diff --git a/packages/generator/tests/fixtures/skip-existing/input/test.txt.blot b/packages/generator/tests/fixtures/skip-existing/input/test.txt.blot new file mode 100644 index 0000000..dd8dd9a --- /dev/null +++ b/packages/generator/tests/fixtures/skip-existing/input/test.txt.blot @@ -0,0 +1 @@ +new diff --git a/packages/generator/tests/fixtures/skip-existing/output/test.txt b/packages/generator/tests/fixtures/skip-existing/output/test.txt new file mode 100644 index 0000000..cbaf024 --- /dev/null +++ b/packages/generator/tests/fixtures/skip-existing/output/test.txt @@ -0,0 +1 @@ +existing diff --git a/packages/generator/tests/fixtures/static/input/test.json.blot b/packages/generator/tests/fixtures/static/input/test.json.blot new file mode 100644 index 0000000..98eef85 --- /dev/null +++ b/packages/generator/tests/fixtures/static/input/test.json.blot @@ -0,0 +1,7 @@ + +const val = 123; + + + +{ "value": <> } + diff --git a/packages/generator/tests/index.spec.ts b/packages/generator/tests/index.spec.ts index edb61a9..b7f2348 100644 --- a/packages/generator/tests/index.spec.ts +++ b/packages/generator/tests/index.spec.ts @@ -1,11 +1,14 @@ import * as fs from "node:fs/promises"; import * as os from "node:os"; import * as path from "node:path"; +import { fileURLToPath } from "node:url"; import { afterEach, expect, test } from "vitest"; import { generate } from "../src/index.ts"; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const fixturesDir = path.join(__dirname, "fixtures"); const testRoots: string[] = []; afterEach(async () => { @@ -15,18 +18,8 @@ afterEach(async () => { }); test("generates a static blot file", async () => { - const { inputDir, outputDir } = await createTestWorkspace(); - await fs.writeFile( - path.join(inputDir, "test.json.blot"), - ` -const val = 123; - - - -{ "value": <> } - -`, - ); + const inputDir = getFixtureInputDir("static"); + const outputDir = await createOutputDir(); const result = await generate({ inputDir, outputDir }); @@ -44,24 +37,8 @@ const val = 123; }); test("generates dynamic file names from getPaths", async () => { - const { inputDir, outputDir } = await createTestWorkspace(); - await fs.writeFile( - path.join(inputDir, "[path].blot"), - ` -import { useParams } from "tempblot"; - -export function getPaths() { - return [{ path: "one.js", val: 1 }, { path: "two.js", val: 2 }]; -} - -const { val } = useParams<{ path: string; val: number }>(); - - - -console.log(<>); - -`, - ); + const inputDir = getFixtureInputDir("dynamic-files"); + const outputDir = await createOutputDir(); await generate({ inputDir, outputDir }); @@ -78,32 +55,8 @@ console.log(2); }); test("generates dynamic directories from _paths.blot", async () => { - const { inputDir, outputDir } = await createTestWorkspace(); - const dynamicDir = path.join(inputDir, "[name]"); - await fs.mkdir(dynamicDir); - await fs.writeFile( - path.join(dynamicDir, "_paths.blot"), - ` -export function getPaths() { - return [{ name: "one" }, { name: "two" }]; -} - -`, - ); - await fs.writeFile( - path.join(dynamicDir, "index.ts.blot"), - ` -import { useParams } from "tempblot"; - -const { name } = useParams<{ name: string }>(); - - - -export const name = "<>"; - -`, - ); - await fs.writeFile(path.join(dynamicDir, "static.txt"), "copied"); + const inputDir = getFixtureInputDir("dynamic-directories"); + const outputDir = await createOutputDir(); await generate({ inputDir, outputDir }); @@ -116,17 +69,16 @@ export const name = "one"; export const name = "two"; `); await expect(fs.readFile(path.join(outputDir, "one", "static.txt"), "utf8")) - .resolves.toBe("copied"); + .resolves.toBe("copied\n"); }); test("skips existing files when requested", async () => { - const { inputDir, outputDir } = await createTestWorkspace(); - await fs.writeFile( - path.join(inputDir, "test.txt.blot"), - `new`, - ); - await fs.mkdir(outputDir); - await fs.writeFile(path.join(outputDir, "test.txt"), "existing"); + const inputDir = getFixtureInputDir("skip-existing"); + const outputDir = await createOutputDir(); + + await fs.cp(getFixtureOutputDir("skip-existing"), outputDir, { + recursive: true, + }); const result = await generate({ inputDir, @@ -135,20 +87,23 @@ test("skips existing files when requested", async () => { }); await expect(fs.readFile(path.join(outputDir, "test.txt"), "utf8")) - .resolves.toBe("existing"); + .resolves.toBe("existing\n"); expect(result.files).toMatchObject([{ action: "skipped" }]); }); -async function createTestWorkspace(): Promise<{ - inputDir: string; - outputDir: string; -}> { +async function createOutputDir(): Promise { const root = await fs.mkdtemp(path.join(os.tmpdir(), "tempblot-generator-")); - const inputDir = path.join(root, "input"); const outputDir = path.join(root, "output"); testRoots.push(root); - await fs.mkdir(inputDir); - return { inputDir, outputDir }; + return outputDir; +} + +function getFixtureInputDir(name: string): string { + return path.join(fixturesDir, name, "input"); +} + +function getFixtureOutputDir(name: string): string { + return path.join(fixturesDir, name, "output"); } -- 2.51.2