2023-03-14 07:07:14 -04:00
|
|
|
import { zipFile } from "@/../tests/utils/zip-utils";
|
|
|
|
import mockFs from "mock-fs";
|
|
|
|
import { ForgeMetadata } from "@/loaders/forge/forge-metadata";
|
|
|
|
import { ForgeMetadataReader } from "@/loaders/forge/forge-metadata-reader";
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
mockFs({
|
|
|
|
"forge.mod.jar": await zipFile([__dirname, "../../../content/forge/mods.toml"], "META-INF/mods.toml"),
|
|
|
|
"text.txt": "",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mockFs.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("ForgeMetadataReader", () => {
|
2024-01-15 07:49:16 -05:00
|
|
|
test("successfully reads mods.toml", async () => {
|
2023-03-14 07:07:14 -04:00
|
|
|
const reader = new ForgeMetadataReader();
|
|
|
|
|
|
|
|
const metadata = await reader.readMetadataFile("forge.mod.jar");
|
|
|
|
|
|
|
|
expect(metadata).toBeInstanceOf(ForgeMetadata);
|
|
|
|
});
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
test("throws if file is not a Forge mod", async () => {
|
2024-01-03 13:30:24 -05:00
|
|
|
const reader = new ForgeMetadataReader();
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
await expect(reader.readMetadataFile("text.txt")).rejects.toThrow();
|
2023-03-14 07:07:14 -04:00
|
|
|
});
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
test("throws if file does not exist", async () => {
|
2023-03-14 07:07:14 -04:00
|
|
|
const reader = new ForgeMetadataReader();
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
await expect(reader.readMetadataFile("text.json")).rejects.toThrow();
|
2023-03-14 07:07:14 -04:00
|
|
|
});
|
|
|
|
});
|