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
This commit is contained in:
Marvin Hagemeister 2024-05-20 15:24:13 +02:00 committed by GitHub
parent d7709daaa0
commit fb3f82b9ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View file

@ -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);
});