test: update modrinth tests

This commit is contained in:
HerozDotExe 2026-06-27 11:52:40 +02:00
parent 9359f0c20a
commit ae37c8fd5e
2 changed files with 64 additions and 49 deletions

View file

@ -1,5 +1,11 @@
import { test } from "vitest"; import { test } from "vitest";
import { Instance, offlineAuth, RuntimeManager, getJavaComponent, importModrinthModpack } from "../../dist/index.js"; import {
Instance,
offlineAuth,
RuntimeManager,
getJavaComponent,
importModrinthModpack,
} from "../../dist/index.js";
import path from "path"; import path from "path";
import fs from "fs/promises"; import fs from "fs/promises";
@ -8,23 +14,29 @@ const gameRoot = path.join(import.meta.dirname, "..", "temp");
// await fs.mkdir(gameRoot, { recursive: true }); // await fs.mkdir(gameRoot, { recursive: true });
test("launch game", { timeout: 0, tags: ["modrinth"] }, async () => { test("launch game", { timeout: 0, tags: ["modrinth"] }, async () => {
const modpack = await importModrinthModpack(
"${modpack_url}",
);
const javaManager = new RuntimeManager(path.join(gameRoot, "java")); const javaManager = new RuntimeManager(path.join(gameRoot, "java"));
javaManager.on("progress", console.log) javaManager.on("progress", console.log);
// const java = await javaManager.use(await getJavaComponent("${version}")) // const java = await javaManager.use(await getJavaComponent("${version}"));
const instance = new Instance({ const instance = new Instance({
auth: offlineAuth("player"), auth: offlineAuth("player"),
paths: { root: gameRoot, instance: path.join(gameRoot, "instances", "${modpack_id}") }, paths: {
root: gameRoot,
instance: path.join(gameRoot, "instances", "${modpack_id}"),
},
javaExecutable: "${java}", javaExecutable: "${java}",
ram: { max: "4G", min: "4G" } ram: { max: "4G", min: "4G" },
}, modrinth: modpack,
await importModrinthModpack("${modpack_url}", "url") });
);
instance.on("progress", console.log); instance.on("progress", console.log);
instance.on("log", (step, msg) => { instance.on("log", (step, msg) => {
console.log(`[${step}] ${msg}`) console.log(`[${step}] ${msg}`);
}) });
await instance.install(); await instance.install();
const p = await instance.launch(); const p = await instance.launch();

View file

@ -8,46 +8,49 @@ const gameRoot = path.join(import.meta.dirname, "..", "temp");
// await fs.mkdir(gameRoot, { recursive: true }); // await fs.mkdir(gameRoot, { recursive: true });
test("launch game", { timeout: 0, tags: ["modrinth"] }, async () => { test("launch game", { timeout: 0, tags: ["modrinth"] }, async () => {
const javaManager = new RuntimeManager(path.join(gameRoot, "java")); const modpack = await importModrinthModpack(
javaManager.on("progress", console.log) "${modpack_url}",
const modpack = );
await importModrinthModpack("${modpack_url}", "url")
const java = await javaManager.use(await getJavaComponent(modpack.version))
const javaManager = new RuntimeManager(path.join(gameRoot, "java"));
javaManager.on("progress", console.log);
const java = await javaManager.use(await getJavaComponent("${version}"));
const instance = new Instance({ const instance = new Instance({
auth: offlineAuth("player"), auth: offlineAuth("player"),
paths: { root: gameRoot, instance: path.join(gameRoot, "instances", "${modpack_id}") }, paths: {
javaExecutable: java, root: gameRoot,
ram: { max: "4G", min: "4G" } instance: path.join(gameRoot, "instances", "${modpack_id}"),
}, },
modpack javaExecutable: java,
); ram: { max: "4G", min: "4G" },
modrinth: modpack,
});
instance.on("progress", console.log); instance.on("progress", console.log);
instance.on("log", (step, msg) => { instance.on("log", (step, msg) => {
console.log(`[${step}] ${msg}`) console.log(`[${step}] ${msg}`);
}) });
await instance.install(); await instance.install();
const p = await instance.launch(); const p = await instance.launch();
p.stdout.on("data", (d: Buffer) => { p.stdout.on("data", (d: Buffer) => {
console.log(d.toString());
});
p.stderr.on("data", (d: Buffer) => {
console.log(d.toString());
});
await new Promise<void>((res) => {
p.on("error", (d: Buffer) => {
console.log(d.toString()); console.log(d.toString());
res();
}); });
p.on("close", () => {
console.log("closed"); p.stderr.on("data", (d: Buffer) => {
res(); console.log(d.toString());
});
await new Promise<void>((res) => {
p.on("error", (d: Buffer) => {
console.log(d.toString());
res();
});
p.on("close", () => {
console.log("closed");
res();
});
}); });
});
}); });