From fb3f82b9eafef7da732c0af7e8a86c3b87075e3c Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 20 May 2024 15:24:13 +0200 Subject: fix(node): track `SIG*` listeners in `process.listeners` (#23890) Some npm libraries like `signal-exit` rely on the length of the listener array returned by `process.listeners("SIGNT")` to be correct to function. We weren't tracking `SIG*` events there, which broke those npm libraries. Fixes https://github.com/denoland/deno/issues/22892 --- tests/unit_node/process_test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/unit_node/process_test.ts') diff --git a/tests/unit_node/process_test.ts b/tests/unit_node/process_test.ts index 0eadb0a16..8f56c92a0 100644 --- a/tests/unit_node/process_test.ts +++ b/tests/unit_node/process_test.ts @@ -1108,3 +1108,19 @@ Deno.test({ process.constructor.call({}); }, }); + +// Test for https://github.com/denoland/deno/issues/22892 +Deno.test("process.listeners - include SIG* events", () => { + const listener = () => console.log("SIGINT"); + process.on("SIGINT", listener); + assertEquals(process.listeners("SIGINT").length, 1); + + const listener2 = () => console.log("SIGINT"); + process.prependListener("SIGINT", listener2); + assertEquals(process.listeners("SIGINT").length, 2); + + process.off("SIGINT", listener); + assertEquals(process.listeners("SIGINT").length, 1); + process.off("SIGINT", listener2); + assertEquals(process.listeners("SIGINT").length, 0); +}); -- cgit v1.2.3