Skip to content

Commit fbd97f0

Browse files
authored
test: can not handle uncaughtException correctly (#12179)
* test: can not handle uncaughtException correctly * test: update
1 parent 67fd33e commit fbd97f0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/rspack-test-tools/src/helper/setup-env.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,24 @@ if (process.env.DEBUG_INFO) {
105105
it = addDebugInfo(it);
106106
}
107107

108+
const uncaughtExceptionListenersLength =
109+
process.listeners("uncaughtException").length;
110+
const unhandledRejectionListenersLength =
111+
process.listeners("unhandledRejection").length;
112+
108113
// cspell:word wabt
109114
// Workaround for a memory leak in wabt
110115
// It leaks an Error object on construction
111116
// so it leaks the whole stack trace
112117
require("wast-loader");
113-
process.removeAllListeners("uncaughtException");
114-
process.removeAllListeners("unhandledRejection");
118+
119+
// remove the last uncaughtException / unhandledRejection listener added by wast-loader
120+
const listeners = process.listeners("uncaughtException");
121+
if (listeners.length > uncaughtExceptionListenersLength) {
122+
process.off("uncaughtException", listeners[listeners.length - 1]);
123+
}
124+
125+
const listeners1 = process.listeners("unhandledRejection");
126+
if (listeners1.length > unhandledRejectionListenersLength) {
127+
process.off("unhandledRejection", listeners1[listeners1.length - 1]);
128+
}

0 commit comments

Comments
 (0)