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 <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
Christopher Hiller
2020-11-11 10:38:43 -08:00
committed by GitHub
parent b5b0437a86
commit 40adb27799

View File

@@ -210,12 +210,10 @@ namespace Harness.Parallel.Worker {
const passes: TestInfo[] = [];
const start = +new Date();
const runner = new Mocha.Runner(suite, /*delay*/ false);
const uncaught = (err: any) => runner.uncaught(err);
runner
.on("start", () => {
unhookUncaughtExceptions(); // turn off global uncaught handling
process.on("unhandledRejection", uncaught); // turn on unhandled rejection handling (not currently handled in mocha)
})
.on("pass", (test: Mocha.Test) => {
passes.push({ name: test.titlePath() });
@@ -224,8 +222,8 @@ namespace Harness.Parallel.Worker {
errors.push({ name: test.titlePath(), error: err.message, stack: err.stack });
})
.on("end", () => {
process.removeListener("unhandledRejection", uncaught);
hookUncaughtExceptions();
runner.dispose();
})
.run(() => {
fn({ task, errors, passes, passing: passes.length, duration: +new Date() - start });