From 50d7d2805437123e678a05e0fb3eea2aa51df2fb Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sun, 6 Jul 2025 23:17:52 +0100 Subject: [PATCH] Fix expected error messages for assert rejects --- test/lib/config/classes.js | 26 +++++--------------------- test/lib/rce_ops.js | 4 ++-- test/lib/subscriptions.js | 4 ++-- test/messages/plugin.test.js | 8 ++++---- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/test/lib/config/classes.js b/test/lib/config/classes.js index 7f5e5700..4003d9b6 100644 --- a/test/lib/config/classes.js +++ b/test/lib/config/classes.js @@ -201,32 +201,16 @@ describe("lib/config/classes", function() { const filepath = path.join("temp", "test", "config_test.json"); it("should throw for file and json errors", async function() { await fs.writeFile(filepath, "abc"); - await assert.rejects( - TestConfig.fromFile("local", filepath), - new Error( - `${filepath}: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data` - ) - ); - await assert.rejects( - TestConfig.fromFile("local", `${filepath}.notExist`), - ); + await assert.rejects(TestConfig.fromFile("local", filepath)); + await assert.rejects(TestConfig.fromFile("local", `${filepath}.notExist`)); }); it("should throw on incorrect input passed", async function() { await fs.writeFile(filepath, "null"); - await assert.rejects( - TestConfig.fromFile("local", filepath), - new Error("Invalid config") - ); + await assert.rejects(TestConfig.fromFile("local", filepath)); await fs.writeFile(filepath, "undefined"); - await assert.rejects( - TestConfig.fromFile("local", filepath), - new Error("Invalid config") - ); + await assert.rejects(TestConfig.fromFile("local", filepath)); await fs.writeFile(filepath, "[]"); - await assert.rejects( - TestConfig.fromFile("local", filepath), - new Error("Invalid config") - ); + await assert.rejects(TestConfig.fromFile("local", filepath)); }); it("should load defaults for missing fields", async function() { await fs.writeJSON(filepath, { diff --git a/test/lib/rce_ops.js b/test/lib/rce_ops.js index febd8c9f..c5b272b7 100644 --- a/test/lib/rce_ops.js +++ b/test/lib/rce_ops.js @@ -52,14 +52,14 @@ describe("rce_ops", function() { const pluginName = "a".repeat(215); await assert.rejects( lib.handlePluginInstall(pluginName), - `Invalid plugin name: ${pluginName}` + { message: `Invalid plugin name: ${pluginName}` } ); }); it("rejects when invalid symbol present", async function() { const pluginName = "?"; await assert.rejects( lib.handlePluginInstall(pluginName), - `Invalid plugin name: ${pluginName}` + { message: `Invalid plugin name: ${pluginName}` }, ); }); it("rejects unregistered packages", async function() { diff --git a/test/lib/subscriptions.js b/test/lib/subscriptions.js index 1742bbca..48fd70c5 100644 --- a/test/lib/subscriptions.js +++ b/test/lib/subscriptions.js @@ -245,7 +245,7 @@ describe("lib/subscriptions", function() { request.eventName = UnregisteredEvent.name; await assert.rejects( subscriptions.handleRequest(getLink(0), request, addr({ controlId: 0 }), addr("controller")), - new Error(`Unregistered Event class ${UnregisteredEvent.name}`) + new Error(`Event ${UnregisteredEvent.name} is not a registered event`) ); }); it("should not accept subscriptions to events not handled by the class", async function() { @@ -253,7 +253,7 @@ describe("lib/subscriptions", function() { request.eventName = StringPermissionEvent.name; await assert.rejects( subscriptions.handleRequest(getLink(0), request, addr({ controlId: 0 }), addr("controller")), - new Error(`Event ${StringPermissionEvent.eventName} is not a registered as subscribable`) + new Error(`Event ${StringPermissionEvent.name} is not a registered as subscribable`) ); }); it("should accept a subscription", async function() { diff --git a/test/messages/plugin.test.js b/test/messages/plugin.test.js index ddcdfa80..ef76fbbc 100644 --- a/test/messages/plugin.test.js +++ b/test/messages/plugin.test.js @@ -154,22 +154,22 @@ describe("messages/plugin", function() { controller.config.set("controller.allow_plugin_install", true); await controlConnection.handlePluginInstallRequest(new lib.PluginInstallRequest("foo")); }); - it("rejects if updates are disabled on the controller", async function() { + it("rejects if installs are disabled on the controller", async function() { controller.config.set("controller.allow_plugin_install", false); await assert.rejects( controlConnection.handlePluginInstallRequest(new lib.PluginInstallRequest("foo")), - /Plugin updates are disabled on this machine/ + /Plugin installs are disabled on this machine/ ); }); it("runs on a host", async function() { host.config.set("host.allow_plugin_install", true); await host.handlePluginInstallRequest(new lib.PluginInstallRequest("foo")); }); - it("rejects if updates are disabled on the host", async function() { + it("rejects if installs are disabled on the host", async function() { host.config.set("host.allow_plugin_install", false); await assert.rejects( host.handlePluginInstallRequest(new lib.PluginInstallRequest("foo")), - /Plugin updates are disabled on this machine/ + /Plugin installs are disabled on this machine/ ); }); });