mc-publish/tests/unit/loaders/fabric/fabric-metadata-reader.spec.ts
Kir_Antipov 22bd9471da Refactored metadata readers
- `ZippedLoaderMetadataReader` was removed
 - Metadata readers now throw instead of returning `undefined`
2024-01-15 15:49:16 +03:00

37 lines
1.1 KiB
TypeScript

import { zipFile } from "@/../tests/utils/zip-utils";
import mockFs from "mock-fs";
import { FabricMetadata } from "@/loaders/fabric/fabric-metadata";
import { FabricMetadataReader } from "@/loaders/fabric/fabric-metadata-reader";
beforeEach(async () => {
mockFs({
"fabric.mod.jar": await zipFile([__dirname, "../../../content/fabric/fabric.mod.json"]),
"text.txt": "",
});
});
afterEach(() => {
mockFs.restore();
});
describe("FabricMetadataReader", () => {
test("successfully reads fabric.mod.json", async () => {
const reader = new FabricMetadataReader();
const metadata = await reader.readMetadataFile("fabric.mod.jar");
expect(metadata).toBeInstanceOf(FabricMetadata);
});
test("throws if file is not a Fabric mod", async () => {
const reader = new FabricMetadataReader();
await expect(reader.readMetadataFile("text.txt")).rejects.toThrow();
});
test("throws if file does not exist", async () => {
const reader = new FabricMetadataReader();
await expect(reader.readMetadataFile("text.json")).rejects.toThrow();
});
});