Skip to content

Commit 2d44c69

Browse files
natemoo-regithub-actions[bot]
authored andcommitted
[ci] format
1 parent 9d2c754 commit 2d44c69

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

src/test-utils.test.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@ import { readFile, writeFile } from "node:fs/promises";
44
import { createFixture } from "./test-utils.ts";
55

66
describe("createFixture", () => {
7-
it("creates files on disk from inline tree", async () => {
8-
const fixture = await createFixture({
9-
"hello.txt": "hello world",
10-
});
11-
const content = await readFile(fixture.resolve("hello.txt"), "utf8");
12-
expect(content).toBe("hello world");
13-
});
7+
it("creates files on disk from inline tree", async () => {
8+
const fixture = await createFixture({
9+
"hello.txt": "hello world",
10+
});
11+
const content = await readFile(fixture.resolve("hello.txt"), "utf8");
12+
expect(content).toBe("hello world");
13+
});
1414

15-
it("creates nested directories from slash-separated keys", async () => {
16-
const fixture = await createFixture({
17-
"src/index.ts": "export const x = 1",
18-
"src/utils/helpers.ts": "export function help() {}",
19-
});
20-
expect(existsSync(fixture.resolve("src/index.ts"))).toBe(true);
21-
expect(existsSync(fixture.resolve("src/utils/helpers.ts"))).toBe(true);
22-
});
15+
it("creates nested directories from slash-separated keys", async () => {
16+
const fixture = await createFixture({
17+
"src/index.ts": "export const x = 1",
18+
"src/utils/helpers.ts": "export function help() {}",
19+
});
20+
expect(existsSync(fixture.resolve("src/index.ts"))).toBe(true);
21+
expect(existsSync(fixture.resolve("src/utils/helpers.ts"))).toBe(true);
22+
});
2323

24-
it("resolve returns absolute path within fixture root", async () => {
25-
const fixture = await createFixture({ "a.txt": "" });
26-
expect(fixture.resolve("a.txt").toString()).toContain(fixture.root.toString());
27-
});
24+
it("resolve returns absolute path within fixture root", async () => {
25+
const fixture = await createFixture({ "a.txt": "" });
26+
expect(fixture.resolve("a.txt").toString()).toContain(fixture.root.toString());
27+
});
2828

29-
it("readFile reads the actual file", async () => {
30-
const fixture = await createFixture({ "a.txt": "Empty" });
31-
expect(await fixture.readFile("a.txt")).toEqual("Empty");
32-
await writeFile(fixture.resolve("a.txt"), "Hello world!", { encoding: "utf-8" });
33-
expect(await fixture.readFile("a.txt")).toEqual("Hello world!");
34-
});
29+
it("readFile reads the actual file", async () => {
30+
const fixture = await createFixture({ "a.txt": "Empty" });
31+
expect(await fixture.readFile("a.txt")).toEqual("Empty");
32+
await writeFile(fixture.resolve("a.txt"), "Hello world!", { encoding: "utf-8" });
33+
expect(await fixture.readFile("a.txt")).toEqual("Hello world!");
34+
});
3535

36-
it("cleanup removes the temp directory", async () => {
37-
const fixture = await createFixture({ "a.txt": "" });
38-
const path = fixture.root;
39-
expect(existsSync(path)).toBe(true);
40-
await fixture.cleanup();
41-
expect(existsSync(path)).toBe(false);
42-
});
36+
it("cleanup removes the temp directory", async () => {
37+
const fixture = await createFixture({ "a.txt": "" });
38+
const path = fixture.root;
39+
expect(existsSync(path)).toBe(true);
40+
await fixture.cleanup();
41+
expect(existsSync(path)).toBe(false);
42+
});
4343
});

src/test-utils.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,35 @@ import { fileURLToPath, pathToFileURL } from "node:url";
66
import { onTestFinished } from "vitest";
77

88
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>;
1313
}
1414

1515
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);
1919

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+
await writeFile(url, content, "utf8");
25+
}
2626

27-
const cleanup = () => rm(path, { recursive: true, force: true });
28-
onTestFinished(cleanup);
27+
const cleanup = () => rm(path, { recursive: true, force: true });
28+
onTestFinished(cleanup);
2929

30-
const resolve = (...segments: string[]) => new URL(`./${segments.join("/")}`, base);
31-
const readFile = (file: PathLike) =>
32-
fsReadFile(new URL(`./${file}`, base), { encoding: "utf-8" });
30+
const resolve = (...segments: string[]) => new URL(`./${segments.join("/")}`, base);
31+
const readFile = (file: PathLike) =>
32+
fsReadFile(new URL(`./${file}`, base), { encoding: "utf-8" });
3333

34-
return {
35-
root: pathToFileURL(path),
36-
resolve,
37-
readFile,
38-
cleanup,
39-
};
34+
return {
35+
root: pathToFileURL(path),
36+
resolve,
37+
readFile,
38+
cleanup,
39+
};
4040
}

0 commit comments

Comments
 (0)