Merge pull request #778 from Cooldude2606/refactor/test-exec-ctl

Refactor execCtl and Ctl to speed up unit testing
This commit is contained in:
Daniel authored and GitHub committed 2025-07-10 13:09:27 +02:00
commit 02d14bd98d
12 files changed
+188 -143

No files matched your search

+5 -21
View File
@@ -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");
assert.rejects(
TestConfig.fromFile("local", filepath),
new Error(
`${filepath}: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data`
)
);
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");
assert.rejects(
TestConfig.fromFile("local", filepath),
new Error("Invalid config")
);
await assert.rejects(TestConfig.fromFile("local", filepath));
await fs.writeFile(filepath, "[]");
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, {
+7 -7
View File
@@ -22,9 +22,9 @@ describe("rce_ops", function() {
await lib.handlePluginUpdate("foo", [{ npmPackage: "foo" }]);
});
it("rejects when plugin not installed", async function() {
assert.rejects(
await assert.rejects(
lib.handlePluginUpdate("foo", []),
"Plugin foo is not installed on this machine"
/Plugin foo is not installed on this machine/
);
});
});
@@ -50,16 +50,16 @@ describe("rce_ops", function() {
});
it("rejects when name too long", async function() {
const pluginName = "a".repeat(215);
assert.rejects(
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 = "?";
assert.rejects(
await assert.rejects(
lib.handlePluginInstall(pluginName),
`Invalid plugin name: ${pluginName}`
{ message: `Invalid plugin name: ${pluginName}` },
);
});
it("rejects unregistered packages", async function() {
@@ -69,7 +69,7 @@ describe("rce_ops", function() {
return { ok: false };
};
assert.rejects(lib.handlePluginInstall("foo"), "Unknown plugin: foo");
await assert.rejects(lib.handlePluginInstall("foo"), /Unknown plugin: foo/);
assert.equal(calledWith, "https://registry.npmjs.com/foo");
});
});
+6 -6
View File
@@ -240,20 +240,20 @@ describe("lib/subscriptions", function() {
subscriptions.handle(RegisteredEvent);
});
it("should not accept subscriptions to unregistered events", function() {
it("should not accept subscriptions to unregistered events", async function() {
const request = new lib.SubscriptionRequest(RegisteredEvent.name, true);
request.eventName = UnregisteredEvent.name;
assert.rejects(
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", function() {
it("should not accept subscriptions to events not handled by the class", async function() {
const request = new lib.SubscriptionRequest(RegisteredEvent.name, true);
request.eventName = StringPermissionEvent.name;
assert.rejects(
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() {