style: format code biome
This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
@@ -2,46 +2,50 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@/lib/services/import/core/download", () => ({
|
||||
downloadFile: vi.fn(async () => ({ ok: true, size: 100 })),
|
||||
downloadFile: vi.fn(async () => ({ ok: true, size: 100 })),
|
||||
}));
|
||||
vi.mock("@/lib/services/pet-source", () => ({
|
||||
CANONICAL_PETS: ["dog", "cat"],
|
||||
resolvePetSwfUrl: vi.fn(async (lib: string) => `https://x/${lib}.swf`),
|
||||
CANONICAL_PETS: ["dog", "cat"],
|
||||
resolvePetSwfUrl: vi.fn(async (lib: string) => `https://x/${lib}.swf`),
|
||||
}));
|
||||
const convertSwfToNitro = vi.fn(() => ({
|
||||
bundle: Buffer.from("nitro"),
|
||||
warnings: [],
|
||||
}));
|
||||
const convertSwfToNitro = vi.fn(() => ({ bundle: Buffer.from("nitro"), warnings: [] }));
|
||||
vi.mock("@/lib/services/swf-to-nitro", () => ({
|
||||
convertSwfToNitro: (...a: unknown[]) => convertSwfToNitro(...(a as Parameters<typeof convertSwfToNitro>)),
|
||||
convertSwfToNitro: (...a: unknown[]) =>
|
||||
convertSwfToNitro(...(a as Parameters<typeof convertSwfToNitro>)),
|
||||
}));
|
||||
vi.mock("node:fs", async (orig) => {
|
||||
const real = (await orig()) as typeof import("node:fs");
|
||||
return {
|
||||
...real,
|
||||
existsSync: vi.fn(() => false),
|
||||
promises: {
|
||||
...real.promises,
|
||||
readFile: vi.fn(async () => Buffer.from("CWS")),
|
||||
writeFile: vi.fn(async () => {}),
|
||||
mkdir: vi.fn(async () => {}),
|
||||
unlink: vi.fn(async () => {}),
|
||||
},
|
||||
};
|
||||
const real = (await orig()) as typeof import("node:fs");
|
||||
return {
|
||||
...real,
|
||||
existsSync: vi.fn(() => false),
|
||||
promises: {
|
||||
...real.promises,
|
||||
readFile: vi.fn(async () => Buffer.from("CWS")),
|
||||
writeFile: vi.fn(async () => {}),
|
||||
mkdir: vi.fn(async () => {}),
|
||||
unlink: vi.fn(async () => {}),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
import { importSinglePet } from "./pet-import";
|
||||
|
||||
describe("pet-import.importSinglePet", () => {
|
||||
it("downloads, converts, writes .nitro", async () => {
|
||||
const r = await importSinglePet({ lib: "dog" });
|
||||
expect(r.ok).toBe(true);
|
||||
expect(convertSwfToNitro).toHaveBeenCalled();
|
||||
});
|
||||
it("downloads, converts, writes .nitro", async () => {
|
||||
const r = await importSinglePet({ lib: "dog" });
|
||||
expect(r.ok).toBe(true);
|
||||
expect(convertSwfToNitro).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("fails cleanly when conversion throws", async () => {
|
||||
convertSwfToNitro.mockImplementationOnce(() => {
|
||||
throw new Error("bad swf");
|
||||
});
|
||||
const r = await importSinglePet({ lib: "cat" });
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.error).toContain("conversion");
|
||||
});
|
||||
it("fails cleanly when conversion throws", async () => {
|
||||
convertSwfToNitro.mockImplementationOnce(() => {
|
||||
throw new Error("bad swf");
|
||||
});
|
||||
const r = await importSinglePet({ lib: "cat" });
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.error).toContain("conversion");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user