mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 00:11:02 -05:00
Made a reader for Fabric metadata
This commit is contained in:
parent
8987e70c81
commit
ba8817193b
2 changed files with 56 additions and 0 deletions
15
src/loaders/fabric/fabric-metadata-reader.ts
Normal file
15
src/loaders/fabric/fabric-metadata-reader.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { ZippedTextLoaderMetadataReader } from "@/loaders/zipped-loader-metadata-reader";
|
||||
import { FabricMetadata } from "./fabric-metadata";
|
||||
import { FABRIC_MOD_JSON, RawFabricMetadata } from "./raw-fabric-metadata";
|
||||
|
||||
/**
|
||||
* A metadata reader that is able to read Fabric mod metadata from a zipped file.
|
||||
*/
|
||||
export class FabricMetadataReader extends ZippedTextLoaderMetadataReader<FabricMetadata, RawFabricMetadata> {
|
||||
/**
|
||||
* Constructs a new {@link FabricMetadataReader} instance.
|
||||
*/
|
||||
constructor() {
|
||||
super(FABRIC_MOD_JSON, FabricMetadata.from, JSON.parse);
|
||||
}
|
||||
}
|
41
tests/unit/loaders/fabric/fabric-metadata-reader.spec.ts
Normal file
41
tests/unit/loaders/fabric/fabric-metadata-reader.spec.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
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("returns undefined if file is not a Fabric mod", async () => {
|
||||
const reader = new FabricMetadataReader();
|
||||
|
||||
const metadata = await reader.readMetadataFile("text.txt");
|
||||
|
||||
expect(metadata).toBeUndefined();
|
||||
});
|
||||
|
||||
test("returns undefined if file does not exist", async () => {
|
||||
const reader = new FabricMetadataReader();
|
||||
|
||||
const metadata = await reader.readMetadataFile("text.json");
|
||||
|
||||
expect(metadata).toBeUndefined();
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue