From 39ed098a648dce7200943b6cf861c87642f4a3c7 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 1 Feb 2023 15:30:01 +0100 Subject: [PATCH] Fix error messages changing with Node.js version Updates to Node.js error reporting have caused tests to fail due to them being hardcoded to expect a certain format that has since changed. Fix by making Node.js create the error message for us. --- test/lib/data/ModPack.js | 8 +++++++- test/lib/plugin_loader.js | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/test/lib/data/ModPack.js b/test/lib/data/ModPack.js index a5c105e5..15f94ee7 100644 --- a/test/lib/data/ModPack.js +++ b/test/lib/data/ModPack.js @@ -82,10 +82,16 @@ describe("lib/data/ModPack", function() { () => ModPack.fromModPackString("AMalformedString"), new Error("Malformed mod pack string: zlib inflate failed") ); + let badJsonMsg; + try { + JSON.parse("Not Json"); + } catch (err) { + badJsonMsg = err.message; + } assert.throws( // eslint-disable-next-line node/no-sync () => ModPack.fromModPackString(Buffer.from(zlib.deflateSync("Not Json")).toString("base64")), - new Error("Malformed mod pack string: Unexpected token N in JSON at position 0") + new Error(`Malformed mod pack string: ${badJsonMsg}`) ); assert.throws( // eslint-disable-next-line node/no-sync diff --git a/test/lib/plugin_loader.js b/test/lib/plugin_loader.js index b5098955..d1153c1b 100644 --- a/test/lib/plugin_loader.js +++ b/test/lib/plugin_loader.js @@ -45,9 +45,16 @@ describe("lib/plugin_loader", function() { ); }); it("should reject on broken plugin", async function() { + let brokenMessage; + try { + // eslint-disable-next-line node/global-require + require(path.resolve(brokenPlugin, "info.js")); + } catch (err) { + brokenMessage = err.message; + } await assert.rejects( libPluginLoader.loadPluginInfos(new Map([["broken", path.resolve(brokenPlugin)]])), - { message: "PluginError: Unexpected identifier" } + { message: `PluginError: ${brokenMessage}` } ); }); it("should reject on invalid plugin", async function() {