[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.

[ci] format

authored by

Nate Moore and committed by
bombshell-bot
(Mar 25, 2026, 1:51 AM UTC) ed017737 59b4e49c

+34 -34
+34 -34
src/test-utils.ts
··· 6 6 import { expect, 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 type FileContent = string | Record<string, unknown> | unknown[]; 16 16 17 17 export async function createFixture<const T extends Record<string, FileContent>>(files: { 18 - [K in keyof T]: K extends `${string}.json` ? FileContent : string; 18 + [K in keyof T]: K extends `${string}.json` ? FileContent : string; 19 19 }): Promise<Fixture> { 20 - const raw = expect.getState().currentTestName ?? "bsh"; 21 - const prefix = raw 22 - .toLowerCase() 23 - .replace(/[^a-z0-9]+/g, "-") 24 - .replace(/^-|-$/g, ""); 25 - const root = new URL(`${prefix}-`, `file://${tmpdir()}/`); 26 - const path = await mkdtemp(fileURLToPath(root)); 27 - const base = pathToFileURL(path + sep); 20 + const raw = expect.getState().currentTestName ?? "bsh"; 21 + const prefix = raw 22 + .toLowerCase() 23 + .replace(/[^a-z0-9]+/g, "-") 24 + .replace(/^-|-$/g, ""); 25 + const root = new URL(`${prefix}-`, `file://${tmpdir()}/`); 26 + const path = await mkdtemp(fileURLToPath(root)); 27 + const base = pathToFileURL(path + sep); 28 28 29 - for (const [name, content] of Object.entries(files as Record<string, FileContent>)) { 30 - const url = new URL(name, base); 31 - const dir = new URL("./", url); 32 - await mkdir(dir, { recursive: true }); 33 - if (name.endsWith(".json") && typeof content !== "string") { 34 - await writeFile(url, JSON.stringify(content, null, 2), "utf8"); 35 - } else { 36 - await writeFile(url, content as string, "utf8"); 37 - } 38 - } 29 + for (const [name, content] of Object.entries(files as Record<string, FileContent>)) { 30 + const url = new URL(name, base); 31 + const dir = new URL("./", url); 32 + await mkdir(dir, { recursive: true }); 33 + if (name.endsWith(".json") && typeof content !== "string") { 34 + await writeFile(url, JSON.stringify(content, null, 2), "utf8"); 35 + } else { 36 + await writeFile(url, content as string, "utf8"); 37 + } 38 + } 39 39 40 - const cleanup = () => rm(path, { recursive: true, force: true }); 41 - onTestFinished(cleanup); 40 + const cleanup = () => rm(path, { recursive: true, force: true }); 41 + onTestFinished(cleanup); 42 42 43 - const resolve = (...segments: string[]) => new URL(`./${segments.join("/")}`, base); 44 - const readFile = (file: PathLike) => 45 - fsReadFile(new URL(`./${file}`, base), { encoding: "utf-8" }); 43 + const resolve = (...segments: string[]) => new URL(`./${segments.join("/")}`, base); 44 + const readFile = (file: PathLike) => 45 + fsReadFile(new URL(`./${file}`, base), { encoding: "utf-8" }); 46 46 47 - return { 48 - root: pathToFileURL(path), 49 - resolve, 50 - readFile, 51 - cleanup, 52 - }; 47 + return { 48 + root: pathToFileURL(path), 49 + resolve, 50 + readFile, 51 + cleanup, 52 + }; 53 53 }