Skip to content

Commit

Permalink
test_runner: avoid unnecessary error creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarchini committed Jan 15, 2025
1 parent eadba47 commit db86232
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,13 +709,16 @@ class Test extends AsyncResource {
return;
}

const cancelledError = this.root.bailed ? new ERR_TEST_FAILURE(
'test bailed out',
kTestBailedOut,
) : new ERR_TEST_FAILURE(
'test did not finish before its parent and was cancelled',
kCancelledByParent,
);
let cancelledError;
if (!error) {
cancelledError = this.root.bailed ? new ERR_TEST_FAILURE(
'test bailed out',
kTestBailedOut,
) : new ERR_TEST_FAILURE(
'test did not finish before its parent and was cancelled',
kCancelledByParent,
);
}

this.fail(error || cancelledError);
this.cancelled = true;
Expand Down Expand Up @@ -773,8 +776,6 @@ class Test extends AsyncResource {

if (this.bail && !this.root.bailed) {
this.root.bailed = true;
this.bailed = true;
this.endTime ??= hrtime();
this.root.postRun();
}
}
Expand Down

0 comments on commit db86232

Please sign in to comment.