Skip to content

Commit 40adb27

Browse files
dispose Mocha Runner after use to avoid MaxlistenersExceededWarning (#41403)
* dispose Mocha Runner after use to avoid MaxlistenersExceededWarning - removed manual `unhandledRejection` listener as Mocha v8.2.0 now has one * Remove ts-ignore comment and commented out line. Co-authored-by: Daniel Rosenwasser <[email protected]>
1 parent b5b0437 commit 40adb27

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/testRunner/parallel/worker.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,10 @@ namespace Harness.Parallel.Worker {
210210
const passes: TestInfo[] = [];
211211
const start = +new Date();
212212
const runner = new Mocha.Runner(suite, /*delay*/ false);
213-
const uncaught = (err: any) => runner.uncaught(err);
214213

215214
runner
216215
.on("start", () => {
217216
unhookUncaughtExceptions(); // turn off global uncaught handling
218-
process.on("unhandledRejection", uncaught); // turn on unhandled rejection handling (not currently handled in mocha)
219217
})
220218
.on("pass", (test: Mocha.Test) => {
221219
passes.push({ name: test.titlePath() });
@@ -224,8 +222,8 @@ namespace Harness.Parallel.Worker {
224222
errors.push({ name: test.titlePath(), error: err.message, stack: err.stack });
225223
})
226224
.on("end", () => {
227-
process.removeListener("unhandledRejection", uncaught);
228225
hookUncaughtExceptions();
226+
runner.dispose();
229227
})
230228
.run(() => {
231229
fn({ task, errors, passes, passing: passes.length, duration: +new Date() - start });

0 commit comments

Comments
 (0)