mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-21 16:00:59 -05:00
Removed NeoForge-related code from forge
This commit is contained in:
parent
22bd9471da
commit
eda9c200e7
4 changed files with 202 additions and 225 deletions
|
@ -101,7 +101,6 @@ const IGNORED_DEPENDENCIES: readonly string[] = [
|
|||
"minecraft",
|
||||
"java",
|
||||
"forge",
|
||||
"neoforge",
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,6 @@ import { PlatformType } from "@/platforms";
|
|||
import { PartialRecord } from "@/utils/types";
|
||||
import { deprecate } from "node:util";
|
||||
import { RawForgeMetadata } from "./raw-forge-metadata";
|
||||
import { getForgeDependencies } from "./forge-dependency";
|
||||
import { asString } from "@/utils/string-utils";
|
||||
|
||||
// _ TODO: Remove the deprecated stuff in v4.0.
|
||||
|
@ -79,16 +78,6 @@ const getLegacyForgeMetadataCustomPayload = deprecate(
|
|||
"Use top-level `mc-publish` field in your mods.toml.",
|
||||
);
|
||||
|
||||
/**
|
||||
* A list of default mod loaders associated with the Forge loader.
|
||||
*/
|
||||
const DEFAULT_FORGE_LOADERS = [LoaderType.FORGE] as const;
|
||||
|
||||
/**
|
||||
* A list of default mod loaders associated with the NeoForge loader.
|
||||
*/
|
||||
const DEFAULT_NEOFORGE_LOADERS = [LoaderType.NEOFORGE] as const;
|
||||
|
||||
/**
|
||||
* Gets an array of supported mod loaders from the custom payload attached to the Forge metadata.
|
||||
*
|
||||
|
@ -98,12 +87,7 @@ const DEFAULT_NEOFORGE_LOADERS = [LoaderType.NEOFORGE] as const;
|
|||
*/
|
||||
export function getLoadersFromForgeMetadataCustomPayload(metadata: RawForgeMetadata): string[] {
|
||||
const payload = getForgeMetadataCustomPayload(metadata);
|
||||
if (payload?.loaders) {
|
||||
return payload.loaders;
|
||||
}
|
||||
|
||||
const isNeoForge = getForgeDependencies(metadata).some(x => x.modId === LoaderType.NEOFORGE);
|
||||
return isNeoForge ? [...DEFAULT_NEOFORGE_LOADERS] : [...DEFAULT_FORGE_LOADERS];
|
||||
return payload.loaders || [LoaderType.FORGE];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { PathLike } from "node:fs";
|
||||
import { parse as parseToml } from "toml";
|
||||
import { readAllZippedText } from "@/utils/io/file-info";
|
||||
import { LoaderType } from "../loader-type";
|
||||
import { LoaderMetadataReader } from "../loader-metadata-reader";
|
||||
import { ForgeMetadata } from "./forge-metadata";
|
||||
import { MODS_TOML } from "./raw-forge-metadata";
|
||||
|
@ -14,6 +15,11 @@ export class ForgeMetadataReader implements LoaderMetadataReader<ForgeMetadata>
|
|||
*/
|
||||
async readMetadataFile(path: PathLike): Promise<ForgeMetadata> {
|
||||
const metadataText = await readAllZippedText(path, MODS_TOML);
|
||||
return ForgeMetadata.from(parseToml(metadataText));
|
||||
const metadata = ForgeMetadata.from(parseToml(metadataText));
|
||||
if (!metadata.dependencies.some(x => x.id === LoaderType.FORGE)) {
|
||||
throw new Error("A Forge metadata file must contain a 'forge' dependency");
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,237 +5,225 @@ import { DependencyType } from "@/dependencies/dependency-type";
|
|||
import { PlatformType } from "@/platforms/platform-type";
|
||||
import { RawForgeMetadata } from "@/loaders/forge/raw-forge-metadata";
|
||||
import { ForgeMetadata } from "@/loaders/forge/forge-metadata";
|
||||
import { LoaderType } from "@/loaders/loader-type";
|
||||
|
||||
function createRawMetadataEntry(loader: LoaderType): { loader: LoaderType, raw: RawForgeMetadata } {
|
||||
const raw = Object.freeze(parseToml(
|
||||
readFileSync(resolvePath(__dirname, `../../../content/${loader}/mods.toml`), "utf8")
|
||||
));
|
||||
|
||||
return Object.freeze({ loader, raw });
|
||||
}
|
||||
|
||||
const RAW_METADATA_ENTRIES = Object.freeze([
|
||||
createRawMetadataEntry(LoaderType.FORGE),
|
||||
createRawMetadataEntry(LoaderType.NEOFORGE),
|
||||
]);
|
||||
const RAW_METADATA: RawForgeMetadata = Object.freeze(parseToml(
|
||||
readFileSync(resolvePath(__dirname, "../../../content/forge/mods.toml"), "utf8")
|
||||
));
|
||||
|
||||
describe("ForgeMetadata", () => {
|
||||
describe.each(RAW_METADATA_ENTRIES)("$loader", ({ loader, raw }) => {
|
||||
describe("from", () => {
|
||||
test("constructs new ForgeMetadata instance using given raw metadata", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
describe("from", () => {
|
||||
test("constructs new ForgeMetadata instance using given raw metadata", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata).toBeInstanceOf(ForgeMetadata);
|
||||
expect(metadata.raw).toBe(raw);
|
||||
});
|
||||
expect(metadata).toBeInstanceOf(ForgeMetadata);
|
||||
expect(metadata.raw).toBe(RAW_METADATA);
|
||||
});
|
||||
});
|
||||
|
||||
describe("id", () => {
|
||||
test("returns id of the mod", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata.id).toBe("example-mod");
|
||||
});
|
||||
});
|
||||
|
||||
describe("name", () => {
|
||||
test("returns name of the mod", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata.name).toBe("Example Mod");
|
||||
});
|
||||
});
|
||||
|
||||
describe("version", () => {
|
||||
test("returns version of the mod", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata.version).toBe("0.1.0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("loaders", () => {
|
||||
test(`returns 'forge' by default`, () => {
|
||||
const rawWithoutLoadersField = {
|
||||
...RAW_METADATA,
|
||||
"mc-publish": {
|
||||
...RAW_METADATA["mc-publish"],
|
||||
loaders: undefined,
|
||||
},
|
||||
};
|
||||
|
||||
const metadata = ForgeMetadata.from(rawWithoutLoadersField);
|
||||
|
||||
expect(metadata.loaders).toEqual(["forge"]);
|
||||
});
|
||||
|
||||
describe("id", () => {
|
||||
test("returns id of the mod", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
test("returns the same value as the 'loaders' field in the custom payload", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata.id).toBe("example-mod");
|
||||
});
|
||||
expect(metadata.loaders).toEqual(["forge", "forge2"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("gameName", () => {
|
||||
test("always returns 'minecraft'", () => {
|
||||
expect(ForgeMetadata.from({} as RawForgeMetadata).gameName).toBe("minecraft");
|
||||
expect(ForgeMetadata.from(RAW_METADATA).gameName).toBe("minecraft");
|
||||
});
|
||||
});
|
||||
|
||||
describe("gameVersions", () => {
|
||||
test("returns an empty array if no dependencies were specified", () => {
|
||||
const metadata = ForgeMetadata.from({} as RawForgeMetadata);
|
||||
|
||||
expect(metadata.gameVersions).toEqual([]);
|
||||
});
|
||||
|
||||
describe("name", () => {
|
||||
test("returns name of the mod", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
test("returns the same value as the 'minecraft' dependency", () => {
|
||||
const metadata = ForgeMetadata.from({ dependencies: { "example-mod": [{ modId: "minecraft", versionRange: "[1.16.5,)" }] } } as unknown as RawForgeMetadata);
|
||||
|
||||
expect(metadata.name).toBe("Example Mod");
|
||||
});
|
||||
expect(metadata.gameVersions).toEqual(["[1.16.5,)"]);
|
||||
});
|
||||
|
||||
describe("version", () => {
|
||||
test("returns version of the mod", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
test("returns the same values as the 'minecraft' dependency", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata.version).toBe("0.1.0");
|
||||
});
|
||||
expect(metadata.gameVersions).toEqual(["[1.17, 1.18)"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dependencies", () => {
|
||||
test("returns an empty array if no dependencies were specified", () => {
|
||||
const metadata = ForgeMetadata.from({} as RawForgeMetadata);
|
||||
|
||||
expect(metadata.dependencies).toEqual([]);
|
||||
});
|
||||
|
||||
describe("loaders", () => {
|
||||
test(`returns '${loader}' by default`, () => {
|
||||
const rawWithoutLoadersField = {
|
||||
...raw,
|
||||
"mc-publish": {
|
||||
...raw["mc-publish"],
|
||||
loaders: undefined,
|
||||
},
|
||||
};
|
||||
test("returns dependencies if they were specified", () => {
|
||||
const metadata = ForgeMetadata.from({ dependencies: { "example-mod": [{ modId: "breaking-mod", versionRange: "*", incompatible: true }] } } as unknown as RawForgeMetadata);
|
||||
|
||||
const metadata = ForgeMetadata.from(rawWithoutLoadersField);
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
expect(metadata.loaders).toEqual([loader]);
|
||||
});
|
||||
|
||||
test("returns the same value as the 'loaders' field in the custom payload", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.loaders).toEqual(["forge", "forge2"]);
|
||||
});
|
||||
expect(dependencies).toHaveLength(1);
|
||||
expect(dependencies[0]).toMatchObject({ id: "breaking-mod", versions: ["*"], type: DependencyType.INCOMPATIBLE });
|
||||
});
|
||||
|
||||
describe("gameName", () => {
|
||||
test("always returns 'minecraft'", () => {
|
||||
expect(ForgeMetadata.from({} as RawForgeMetadata).gameName).toBe("minecraft");
|
||||
expect(ForgeMetadata.from(raw).gameName).toBe("minecraft");
|
||||
});
|
||||
});
|
||||
test("regular dependencies have no aliases", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
describe("gameVersions", () => {
|
||||
test("returns an empty array if no dependencies were specified", () => {
|
||||
const metadata = ForgeMetadata.from({} as RawForgeMetadata);
|
||||
|
||||
expect(metadata.gameVersions).toEqual([]);
|
||||
});
|
||||
|
||||
test("returns the same value as the 'minecraft' dependency", () => {
|
||||
const metadata = ForgeMetadata.from({ dependencies: { "example-mod": [{ modId: "minecraft", versionRange: "[1.16.5,)" }] } } as unknown as RawForgeMetadata);
|
||||
|
||||
expect(metadata.gameVersions).toEqual(["[1.16.5,)"]);
|
||||
});
|
||||
|
||||
test("returns the same values as the 'minecraft' dependency", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.gameVersions).toEqual(["[1.17, 1.18)"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dependencies", () => {
|
||||
test("returns an empty array if no dependencies were specified", () => {
|
||||
const metadata = ForgeMetadata.from({} as RawForgeMetadata);
|
||||
|
||||
expect(metadata.dependencies).toEqual([]);
|
||||
});
|
||||
|
||||
test("returns dependencies if they were specified", () => {
|
||||
const metadata = ForgeMetadata.from({ dependencies: { "example-mod": [{ modId: "breaking-mod", versionRange: "*", incompatible: true }] } } as unknown as RawForgeMetadata);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
expect(dependencies).toHaveLength(1);
|
||||
expect(dependencies[0]).toMatchObject({ id: "breaking-mod", versions: ["*"], type: DependencyType.INCOMPATIBLE });
|
||||
});
|
||||
|
||||
test("regular dependencies have no aliases", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
const regularDependencies = ["included-mod", "conflicting-mod", "breaking-mod"].map(id => dependencies.find(x => x.id === id));
|
||||
|
||||
for (const dependency of regularDependencies) {
|
||||
for (const platform of PlatformType.values()) {
|
||||
expect(dependency?.getProjectId(platform)).toBe(dependency.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test(`special dependencies ('${loader}', 'minecraft', 'java') are ignored by default`, () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
expect(dependencies.find(x => x.id === loader)?.isIgnored()).toBe(true);
|
||||
expect(dependencies.find(x => x.id === "minecraft")?.isIgnored()).toBe(true);
|
||||
expect(dependencies.find(x => x.id === "java")?.isIgnored()).toBe(true);
|
||||
});
|
||||
|
||||
test("regular dependencies are not ignored by default", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
expect(dependencies.find(x => x.id === "included-mod")?.isIgnored()).toBe(false);
|
||||
expect(dependencies.find(x => x.id === "suggested-mod")?.isIgnored()).toBe(false);
|
||||
expect(dependencies.find(x => x.id === "conflicting-mod")?.isIgnored()).toBe(false);
|
||||
expect(dependencies.find(x => x.id === "breaking-mod")?.isIgnored()).toBe(false);
|
||||
});
|
||||
|
||||
test("returns dependencies merged with the 'dependencies' declaration from the custom payload", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
expect(dependencies).toHaveLength(8);
|
||||
expect(dependencies.find(x => x.id === loader)).toMatchObject({ versions: ["[34,)"], type: DependencyType.REQUIRED });
|
||||
expect(dependencies.find(x => x.id === "minecraft")).toMatchObject({ versions: ["[1.17, 1.18)"], type: DependencyType.REQUIRED });
|
||||
expect(dependencies.find(x => x.id === "java")).toMatchObject({ versions: ["[16,)"], type: DependencyType.REQUIRED });
|
||||
expect(dependencies.find(x => x.id === "recommended-mod")).toMatchObject({ versions: ["0.2.0"], type: DependencyType.RECOMMENDED });
|
||||
expect(dependencies.find(x => x.id === "included-mod")).toMatchObject({ versions: ["*"], type: DependencyType.EMBEDDED });
|
||||
expect(dependencies.find(x => x.id === "suggested-mod")).toMatchObject({ versions: ["*"], type: DependencyType.OPTIONAL });
|
||||
expect(dependencies.find(x => x.id === "conflicting-mod")).toMatchObject({ versions: ["<0.40.0"], type: DependencyType.CONFLICTING });
|
||||
expect(dependencies.find(x => x.id === "breaking-mod")).toMatchObject({ versions: ["*"], type: DependencyType.INCOMPATIBLE });
|
||||
|
||||
const merged = dependencies.find(x => x.id === "recommended-mod");
|
||||
expect(merged.getProjectId(PlatformType.MODRINTH)).toBe("AAAA");
|
||||
expect(merged.getProjectId(PlatformType.CURSEFORGE)).toBe("42");
|
||||
expect(merged.getProjectId(PlatformType.GITHUB)).toBe("v0.2.0");
|
||||
expect(merged.isIgnored()).toBe(true);
|
||||
|
||||
const withMetadata = dependencies.find(x => x.id === "suggested-mod");
|
||||
expect(withMetadata.getProjectId(PlatformType.MODRINTH)).toBe("BBBB");
|
||||
expect(withMetadata.getProjectId(PlatformType.CURSEFORGE)).toBe("43");
|
||||
expect(withMetadata.getProjectId(PlatformType.GITHUB)).toBe("v0.3.0");
|
||||
expect(withMetadata.isIgnored()).toBe(false);
|
||||
expect(withMetadata.isIgnored(PlatformType.CURSEFORGE)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod", () => {
|
||||
test("returns the main mod entry in the metadata", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.mod?.modId).toBe("example-mod");
|
||||
});
|
||||
|
||||
test("returns an empty mod entry if no mods were specified in the metadata", () => {
|
||||
const metadata = ForgeMetadata.from({} as RawForgeMetadata);
|
||||
|
||||
expect(metadata.mod).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe("raw", () => {
|
||||
test("returns the raw metadata oject this instance was created from", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.raw).toBe(raw);
|
||||
});
|
||||
});
|
||||
|
||||
describe("customPayload", () => {
|
||||
test("returns an empty object by default", () => {
|
||||
const metadata = ForgeMetadata.from({} as RawForgeMetadata);
|
||||
|
||||
expect(metadata.customPayload).toEqual({});
|
||||
});
|
||||
|
||||
test("return the custom payload if it was specified", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.customPayload?.loaders).toEqual(["forge", "forge2"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getProjectId", () => {
|
||||
test("returns the mod id by default", () => {
|
||||
const metadata = ForgeMetadata.from({ mods: [{ modId: "example-mod" }] } as RawForgeMetadata);
|
||||
const dependencies = metadata.dependencies;
|
||||
const regularDependencies = ["included-mod", "conflicting-mod", "breaking-mod"].map(id => dependencies.find(x => x.id === id));
|
||||
|
||||
for (const dependency of regularDependencies) {
|
||||
for (const platform of PlatformType.values()) {
|
||||
expect(metadata.getProjectId(platform)).toBe("example-mod");
|
||||
expect(dependency?.getProjectId(platform)).toBe(dependency.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("returns the same value as one specified in the custom payload", () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
test(`special dependencies ('forge', 'minecraft', 'java') are ignored by default`, () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata.getProjectId(PlatformType.MODRINTH)).toBe("AANobbMI");
|
||||
expect(metadata.getProjectId(PlatformType.CURSEFORGE)).toBe("394468");
|
||||
expect(metadata.getProjectId(PlatformType.GITHUB)).toBe("mc1.18-0.4.0-alpha5");
|
||||
});
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
expect(dependencies.find(x => x.id === "forge")?.isIgnored()).toBe(true);
|
||||
expect(dependencies.find(x => x.id === "minecraft")?.isIgnored()).toBe(true);
|
||||
expect(dependencies.find(x => x.id === "java")?.isIgnored()).toBe(true);
|
||||
});
|
||||
|
||||
test("regular dependencies are not ignored by default", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
expect(dependencies.find(x => x.id === "included-mod")?.isIgnored()).toBe(false);
|
||||
expect(dependencies.find(x => x.id === "suggested-mod")?.isIgnored()).toBe(false);
|
||||
expect(dependencies.find(x => x.id === "conflicting-mod")?.isIgnored()).toBe(false);
|
||||
expect(dependencies.find(x => x.id === "breaking-mod")?.isIgnored()).toBe(false);
|
||||
});
|
||||
|
||||
test("returns dependencies merged with the 'dependencies' declaration from the custom payload", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
expect(dependencies).toHaveLength(8);
|
||||
expect(dependencies.find(x => x.id === "forge")).toMatchObject({ versions: ["[34,)"], type: DependencyType.REQUIRED });
|
||||
expect(dependencies.find(x => x.id === "minecraft")).toMatchObject({ versions: ["[1.17, 1.18)"], type: DependencyType.REQUIRED });
|
||||
expect(dependencies.find(x => x.id === "java")).toMatchObject({ versions: ["[16,)"], type: DependencyType.REQUIRED });
|
||||
expect(dependencies.find(x => x.id === "recommended-mod")).toMatchObject({ versions: ["0.2.0"], type: DependencyType.RECOMMENDED });
|
||||
expect(dependencies.find(x => x.id === "included-mod")).toMatchObject({ versions: ["*"], type: DependencyType.EMBEDDED });
|
||||
expect(dependencies.find(x => x.id === "suggested-mod")).toMatchObject({ versions: ["*"], type: DependencyType.OPTIONAL });
|
||||
expect(dependencies.find(x => x.id === "conflicting-mod")).toMatchObject({ versions: ["<0.40.0"], type: DependencyType.CONFLICTING });
|
||||
expect(dependencies.find(x => x.id === "breaking-mod")).toMatchObject({ versions: ["*"], type: DependencyType.INCOMPATIBLE });
|
||||
|
||||
const merged = dependencies.find(x => x.id === "recommended-mod");
|
||||
expect(merged.getProjectId(PlatformType.MODRINTH)).toBe("AAAA");
|
||||
expect(merged.getProjectId(PlatformType.CURSEFORGE)).toBe("42");
|
||||
expect(merged.getProjectId(PlatformType.GITHUB)).toBe("v0.2.0");
|
||||
expect(merged.isIgnored()).toBe(true);
|
||||
|
||||
const withMetadata = dependencies.find(x => x.id === "suggested-mod");
|
||||
expect(withMetadata.getProjectId(PlatformType.MODRINTH)).toBe("BBBB");
|
||||
expect(withMetadata.getProjectId(PlatformType.CURSEFORGE)).toBe("43");
|
||||
expect(withMetadata.getProjectId(PlatformType.GITHUB)).toBe("v0.3.0");
|
||||
expect(withMetadata.isIgnored()).toBe(false);
|
||||
expect(withMetadata.isIgnored(PlatformType.CURSEFORGE)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod", () => {
|
||||
test("returns the main mod entry in the metadata", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata.mod?.modId).toBe("example-mod");
|
||||
});
|
||||
|
||||
test("returns an empty mod entry if no mods were specified in the metadata", () => {
|
||||
const metadata = ForgeMetadata.from({} as RawForgeMetadata);
|
||||
|
||||
expect(metadata.mod).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe("raw", () => {
|
||||
test("returns the raw metadata oject this instance was created from", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata.raw).toBe(RAW_METADATA);
|
||||
});
|
||||
});
|
||||
|
||||
describe("customPayload", () => {
|
||||
test("returns an empty object by default", () => {
|
||||
const metadata = ForgeMetadata.from({} as RawForgeMetadata);
|
||||
|
||||
expect(metadata.customPayload).toEqual({});
|
||||
});
|
||||
|
||||
test("return the custom payload if it was specified", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata.customPayload?.loaders).toEqual(["forge", "forge2"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getProjectId", () => {
|
||||
test("returns the mod id by default", () => {
|
||||
const metadata = ForgeMetadata.from({ mods: [{ modId: "example-mod" }] } as RawForgeMetadata);
|
||||
|
||||
for (const platform of PlatformType.values()) {
|
||||
expect(metadata.getProjectId(platform)).toBe("example-mod");
|
||||
}
|
||||
});
|
||||
|
||||
test("returns the same value as one specified in the custom payload", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
|
||||
expect(metadata.getProjectId(PlatformType.MODRINTH)).toBe("AANobbMI");
|
||||
expect(metadata.getProjectId(PlatformType.CURSEFORGE)).toBe("394468");
|
||||
expect(metadata.getProjectId(PlatformType.GITHUB)).toBe("mc1.18-0.4.0-alpha5");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue