refactor: 🚨 Don't use wildcard imports

This commit is contained in:
Jesse Wierzbinski 2024-10-03 13:44:55 +02:00
parent bec3e4ea70
commit 53688095cc
No known key found for this signature in database

View file

@ -12,8 +12,8 @@ import {
mock, mock,
spyOn, spyOn,
} from "bun:test"; } from "bun:test";
import * as fs from "node:fs/promises"; import { rm } from "node:fs/promises";
import * as path from "node:path"; import { join } from "node:path";
import type { Config } from "~/packages/config-manager/config.type"; import type { Config } from "~/packages/config-manager/config.type";
import type { MediaHasher } from "../media-hasher"; import type { MediaHasher } from "../media-hasher";
import { DiskMediaDriver } from "./disk"; import { DiskMediaDriver } from "./disk";
@ -67,12 +67,12 @@ describe("DiskMediaDriver", () => {
expect(mockMediaHasher.getMediaHash).toHaveBeenCalledWith(file); expect(mockMediaHasher.getMediaHash).toHaveBeenCalledWith(file);
expect(bunWriteSpy).toHaveBeenCalledWith( expect(bunWriteSpy).toHaveBeenCalledWith(
path.join("/test/uploads", "testhash", "test.webp"), join("/test/uploads", "testhash", "test.webp"),
expect.any(ArrayBuffer), expect.any(ArrayBuffer),
); );
expect(result).toEqual({ expect(result).toEqual({
uploadedFile: file, uploadedFile: file,
path: path.join("testhash", "test.webp"), path: join("testhash", "test.webp"),
hash: "testhash", hash: "testhash",
}); });
}); });
@ -103,7 +103,7 @@ describe("DiskMediaDriver", () => {
expect(databaseHashFetcher).toHaveBeenCalledWith(hash); expect(databaseHashFetcher).toHaveBeenCalledWith(hash);
expect(Bun.file).toHaveBeenCalledWith( expect(Bun.file).toHaveBeenCalledWith(
path.join("/test/uploads", "test.webp"), join("/test/uploads", "test.webp"),
); );
expect(result).toBeInstanceOf(File); expect(result).toBeInstanceOf(File);
expect(result?.name).toBe("test.webp"); expect(result?.name).toBe("test.webp");
@ -114,9 +114,7 @@ describe("DiskMediaDriver", () => {
const filename = "test.webp"; const filename = "test.webp";
const result = await diskDriver.getFile(filename); const result = await diskDriver.getFile(filename);
expect(Bun.file).toHaveBeenCalledWith( expect(Bun.file).toHaveBeenCalledWith(join("/test/uploads", filename));
path.join("/test/uploads", filename),
);
expect(result).toBeInstanceOf(File); expect(result).toBeInstanceOf(File);
expect(result?.name).toBe(filename); expect(result?.name).toBe(filename);
expect(result?.type).toBe("image/webp"); expect(result?.type).toBe("image/webp");
@ -126,9 +124,8 @@ describe("DiskMediaDriver", () => {
const url = "http://localhost:3000/uploads/testhash/test.webp"; const url = "http://localhost:3000/uploads/testhash/test.webp";
await diskDriver.deleteFileByUrl(url); await diskDriver.deleteFileByUrl(url);
expect(fs.rm).toHaveBeenCalledWith( expect(rm).toHaveBeenCalledWith(join("/test/uploads", "testhash"), {
path.join("/test/uploads", "testhash"), recursive: true,
{ recursive: true }, });
);
}); });
}); });