Skip to content

Commit db86232

Browse files
committed
test_runner: avoid unnecessary error creation
1 parent eadba47 commit db86232

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
@@ -709,13 +709,16 @@ class Test extends AsyncResource {
709709
return;
710710
}
711711

712-
const cancelledError = this.root.bailed ? new ERR_TEST_FAILURE(
713-
'test bailed out',
714-
kTestBailedOut,
715-
) : new ERR_TEST_FAILURE(
716-
'test did not finish before its parent and was cancelled',
717-
kCancelledByParent,
718-
);
712+
let cancelledError;
713+
if (!error) {
714+
cancelledError = this.root.bailed ? new ERR_TEST_FAILURE(
715+
'test bailed out',
716+
kTestBailedOut,
717+
) : new ERR_TEST_FAILURE(
718+
'test did not finish before its parent and was cancelled',
719+
kCancelledByParent,
720+
);
721+
}
719722

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

774777
if (this.bail && !this.root.bailed) {
775778
this.root.bailed = true;
776-
this.bailed = true;
777-
this.endTime ??= hrtime();
778779
this.root.postRun();
779780
}
780781
}

0 commit comments

Comments
 (0)