Skip to content
Prev Previous commit
Next Next commit
do not recreate on each test
  • Loading branch information
rluvaton committed Jul 18, 2023
commit eeabcf55cad59ad699c76996b3e5befc3cca85ba
19 changes: 11 additions & 8 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,21 @@ class Test extends AsyncResource {
return;
}

this.#abortController.abort();
// Do not run for hooks and root test as hooks instance are shared between tests suite so aborting them will
// abort cause them to not run for further tests.
if (this.parent !== null) {
this.#abortController.abort();
}

await afterEach();
await after();
this.pass();
} catch (err) {
this.#abortController.abort();
// Do not run for hooks and root test as hooks instance are shared between tests suite so aborting them will
// abort cause them to not run for further tests.
if (this.parent !== null) {
this.#abortController.abort();
}
try { await afterEach(); } catch { /* test is already failing, let's ignore the error */ }
try { await after(); } catch { /* Ignore error. */ }
if (isTestFailureError(err)) {
Expand Down Expand Up @@ -746,11 +754,6 @@ class Test extends AsyncResource {
this.parent.reportStarted();
this.reporter.start(this.nesting, kFilename, this.name);
}

recreateAbortController() {
this.#abortController = new AbortController();
this.signal = this.#abortController.signal;
}
}

class TestHook extends Test {
Expand All @@ -774,7 +777,7 @@ class TestHook extends Test {
}
postRun() {
// Need to recreate the abort controller because we abort each time in the end
super.recreateAbortController();
// super.recreateAbortController();
}
}

Expand Down