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