Skip to content

Commit 791fb5e

Browse files
committed
test_runner: avoid unnecessary error creation
1 parent 26ebbb2 commit 791fb5e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/internal/test_runner/test.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -773,13 +773,16 @@ class Test extends AsyncResource {
773773
return;
774774
}
775775

776-
const cancelledError = this.root.bailed ? new ERR_TEST_FAILURE(
777-
'test bailed out',
778-
kTestBailedOut,
779-
) : new ERR_TEST_FAILURE(
780-
'test did not finish before its parent and was cancelled',
781-
kCancelledByParent,
782-
);
776+
let cancelledError;
777+
if (!error) {
778+
cancelledError = this.root.bailed ? new ERR_TEST_FAILURE(
779+
'test bailed out',
780+
kTestBailedOut,
781+
) : new ERR_TEST_FAILURE(
782+
'test did not finish before its parent and was cancelled',
783+
kCancelledByParent,
784+
);
785+
}
783786

784787
this.fail(error || cancelledError);
785788
this.cancelled = true;
@@ -837,8 +840,6 @@ class Test extends AsyncResource {
837840

838841
if (this.bail && !this.root.bailed) {
839842
this.root.bailed = true;
840-
this.bailed = true;
841-
this.endTime ??= hrtime();
842843
this.root.postRun();
843844
}
844845
}

0 commit comments

Comments
 (0)