[READ-ONLY] Mirror of https://github.com/bombshell-dev/tools. Internal CLI to standardize tooling across all Bombshell projects
0

Configure Feed

Select the types of activity you want to include in your feed.

feat(test-utils): automatically serialize json

Nate Moore (Mar 24, 2026, 9:18 PM EDT) c32ed0f0 2d44c699

+28 -24
+28 -24
src/test-utils.ts
··· 6 6 import { onTestFinished } from "vitest"; 7 7 8 8 export interface Fixture { 9 - root: URL; 10 - resolve: (...segments: string[]) => URL; 11 - readFile: (file: PathLike) => Promise<string>; 12 - cleanup: () => Promise<void>; 9 + root: URL; 10 + resolve: (...segments: string[]) => URL; 11 + readFile: (file: PathLike) => Promise<string>; 12 + cleanup: () => Promise<void>; 13 13 } 14 14 15 15 export async function createFixture(files: Record<string, string>): Promise<Fixture> { 16 - const root = new URL(`bsh-`, `file://${tmpdir()}/`); 17 - const path = await mkdtemp(fileURLToPath(root)); 18 - const base = pathToFileURL(path + sep); 16 + const root = new URL(`bsh-`, `file://${tmpdir()}/`); 17 + const path = await mkdtemp(fileURLToPath(root)); 18 + const base = pathToFileURL(path + sep); 19 19 20 - for (const [name, content] of Object.entries(files)) { 21 - const url = new URL(name, base); 22 - const dir = new URL("./", url); 23 - await mkdir(dir, { recursive: true }); 24 - await writeFile(url, content, "utf8"); 25 - } 20 + for (const [name, content] of Object.entries(files)) { 21 + const url = new URL(name, base); 22 + const dir = new URL("./", url); 23 + await mkdir(dir, { recursive: true }); 24 + if (name.endsWith(".json") && typeof content !== "string") { 25 + await writeFile(url, JSON.stringify(content, null, 2), "utf8"); 26 + } else { 27 + await writeFile(url, content, "utf8"); 28 + } 29 + } 26 30 27 - const cleanup = () => rm(path, { recursive: true, force: true }); 28 - onTestFinished(cleanup); 31 + const cleanup = () => rm(path, { recursive: true, force: true }); 32 + onTestFinished(cleanup); 29 33 30 - const resolve = (...segments: string[]) => new URL(`./${segments.join("/")}`, base); 31 - const readFile = (file: PathLike) => 32 - fsReadFile(new URL(`./${file}`, base), { encoding: "utf-8" }); 34 + const resolve = (...segments: string[]) => new URL(`./${segments.join("/")}`, base); 35 + const readFile = (file: PathLike) => 36 + fsReadFile(new URL(`./${file}`, base), { encoding: "utf-8" }); 33 37 34 - return { 35 - root: pathToFileURL(path), 36 - resolve, 37 - readFile, 38 - cleanup, 39 - }; 38 + return { 39 + root: pathToFileURL(path), 40 + resolve, 41 + readFile, 42 + cleanup, 43 + }; 40 44 }