2023-03-21 05:34:46 -04:00
|
|
|
import { zipFile } from "@/../tests/utils/zip-utils";
|
|
|
|
import mockFs from "mock-fs";
|
|
|
|
import { QuiltMetadata } from "@/loaders/quilt/quilt-metadata";
|
|
|
|
import { QuiltMetadataReader } from "@/loaders/quilt/quilt-metadata-reader";
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
mockFs({
|
|
|
|
"quilt.mod.jar": await zipFile([__dirname, "../../../content/quilt/quilt.mod.json"]),
|
|
|
|
"text.txt": "",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mockFs.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("QuiltMetadataReader", () => {
|
|
|
|
test("successfully reads quilt.mod.json", async () => {
|
|
|
|
const reader = new QuiltMetadataReader();
|
|
|
|
|
|
|
|
const metadata = await reader.readMetadataFile("quilt.mod.jar");
|
|
|
|
|
|
|
|
expect(metadata).toBeInstanceOf(QuiltMetadata);
|
|
|
|
});
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
test("throws if file is not a Quilt mod", async () => {
|
2023-03-21 05:34:46 -04:00
|
|
|
const reader = new QuiltMetadataReader();
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
await expect(reader.readMetadataFile("text.txt")).rejects.toThrow();
|
2023-03-21 05:34:46 -04:00
|
|
|
});
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
test("throws if file does not exist", async () => {
|
2023-03-21 05:34:46 -04:00
|
|
|
const reader = new QuiltMetadataReader();
|
|
|
|
|
2024-01-15 07:49:16 -05:00
|
|
|
await expect(reader.readMetadataFile("text.json")).rejects.toThrow();
|
2023-03-21 05:34:46 -04:00
|
|
|
});
|
|
|
|
});
|