From ed017737ac1de998fdf4cb74232c18afa1360504 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 25 Mar 2026 01:51:59 +0000 Subject: [PATCH] [ci] format --- src/test-utils.ts | 68 +++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/test-utils.ts b/src/test-utils.ts index ba9e827..ca2d4ea 100644 --- a/src/test-utils.ts +++ b/src/test-utils.ts @@ -6,48 +6,48 @@ import { fileURLToPath, pathToFileURL } from "node:url"; import { expect, onTestFinished } from "vitest"; export interface Fixture { - root: URL; - resolve: (...segments: string[]) => URL; - readFile: (file: PathLike) => Promise; - cleanup: () => Promise; + root: URL; + resolve: (...segments: string[]) => URL; + readFile: (file: PathLike) => Promise; + cleanup: () => Promise; } type FileContent = string | Record | unknown[]; export async function createFixture>(files: { - [K in keyof T]: K extends `${string}.json` ? FileContent : string; + [K in keyof T]: K extends `${string}.json` ? FileContent : string; }): Promise { - const raw = expect.getState().currentTestName ?? "bsh"; - const prefix = raw - .toLowerCase() - .replace(/[^a-z0-9]+/g, "-") - .replace(/^-|-$/g, ""); - const root = new URL(`${prefix}-`, `file://${tmpdir()}/`); - const path = await mkdtemp(fileURLToPath(root)); - const base = pathToFileURL(path + sep); + const raw = expect.getState().currentTestName ?? "bsh"; + const prefix = raw + .toLowerCase() + .replace(/[^a-z0-9]+/g, "-") + .replace(/^-|-$/g, ""); + const root = new URL(`${prefix}-`, `file://${tmpdir()}/`); + const path = await mkdtemp(fileURLToPath(root)); + const base = pathToFileURL(path + sep); - for (const [name, content] of Object.entries(files as Record)) { - const url = new URL(name, base); - const dir = new URL("./", url); - await mkdir(dir, { recursive: true }); - if (name.endsWith(".json") && typeof content !== "string") { - await writeFile(url, JSON.stringify(content, null, 2), "utf8"); - } else { - await writeFile(url, content as string, "utf8"); - } - } + for (const [name, content] of Object.entries(files as Record)) { + const url = new URL(name, base); + const dir = new URL("./", url); + await mkdir(dir, { recursive: true }); + if (name.endsWith(".json") && typeof content !== "string") { + await writeFile(url, JSON.stringify(content, null, 2), "utf8"); + } else { + await writeFile(url, content as string, "utf8"); + } + } - const cleanup = () => rm(path, { recursive: true, force: true }); - onTestFinished(cleanup); + const cleanup = () => rm(path, { recursive: true, force: true }); + onTestFinished(cleanup); - const resolve = (...segments: string[]) => new URL(`./${segments.join("/")}`, base); - const readFile = (file: PathLike) => - fsReadFile(new URL(`./${file}`, base), { encoding: "utf-8" }); + const resolve = (...segments: string[]) => new URL(`./${segments.join("/")}`, base); + const readFile = (file: PathLike) => + fsReadFile(new URL(`./${file}`, base), { encoding: "utf-8" }); - return { - root: pathToFileURL(path), - resolve, - readFile, - cleanup, - }; + return { + root: pathToFileURL(path), + resolve, + readFile, + cleanup, + }; } -- 2.51.2