2023-03-05 04:37:24 -05:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
test("throws if file is not a Fabric mod", async () => {
|
2023-03-05 04:37:24 -05:00
|
|
|
const reader = new FabricMetadataReader();
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
await expect(reader.readMetadataFile("text.txt")).rejects.toThrow();
|
2023-03-05 04:37:24 -05:00
|
|
|
});
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
test("throws if file does not exist", async () => {
|
2023-03-05 04:37:24 -05:00
|
|
|
const reader = new FabricMetadataReader();
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
await expect(reader.readMetadataFile("text.json")).rejects.toThrow();
|
2023-03-05 04:37:24 -05:00
|
|
|
});
|
|
|
|
});
|