feat: add a function to handle log4j fix and its test, add it to arguments.ts and finish arguments.test.ts

This commit is contained in:
HerozDotExe 2025-10-30 23:30:31 +01:00
parent 976838bd3c
commit 71ccc0cbeb
5 changed files with 82 additions and 20 deletions

File diff suppressed because one or more lines are too long

34
tests/log4j.test.ts Normal file
View file

@ -0,0 +1,34 @@
import { expect, test, vi } from "vitest";
import * as nlk from "../dist/index.js";
import path from "path";
import { hash } from "crypto";
import fs from "fs/promises";
const root = path.join(import.meta.dirname, "temp");
const xmlFile = path.join(root, "client-1.21.2.xml");
try {
await fs.rm(xmlFile, { recursive: true });
} catch {
// first time the test is runned
}
// mock os to linux for testing
vi.stubGlobal("process", { platform: "linux" });
test(
"download xml file and return correct arguments",
{ timeout: 10000 },
async () => {
const versionManifest = await nlk.core.version.getVersionManifest("1.21.8");
const arg = await nlk.core.log4j.getArgument(versionManifest, root);
expect(arg, "correct arg returned").toBe(
`-Dlog4j.configurationFile=${xmlFile}`,
);
expect(
hash("sha1", await fs.readFile(xmlFile, { encoding: "utf-8" })),
"correct hash",
).toBe("39384bd14c0606d812afec88d8aff595b2587dd9");
},
);