Skip to content

Commit 07e4a42

Browse files
cjihrigmarco-ippolito
authored andcommitted
test_runner: simplify test start time tracking
This commit simplifies the logic for tracking test start time. The start time is now set only when a test/suite begins running. If the test/suite never runs, a fallback is provided in postRun(). PR-URL: #52182 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
1 parent 8ba308a commit 07e4a42

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lib/internal/test_runner/test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ class Test extends AsyncResource {
454454
}
455455

456456
if (preventAddingSubtests) {
457-
test.startTime = test.startTime || hrtime();
458457
test.fail(
459458
new ERR_TEST_FAILURE(
460459
'test could not be started because its parent finished',
@@ -484,7 +483,6 @@ class Test extends AsyncResource {
484483
kCancelledByParent,
485484
),
486485
);
487-
this.startTime = this.startTime || this.endTime; // If a test was canceled before it was started, e.g inside a hook
488486
this.cancelled = true;
489487
this.abortController.abort();
490488
}
@@ -700,12 +698,13 @@ class Test extends AsyncResource {
700698
}
701699

702700
postRun(pendingSubtestsError) {
701+
this.startTime ??= hrtime();
702+
703703
// If the test was failed before it even started, then the end time will
704704
// be earlier than the start time. Correct that here.
705705
if (this.endTime < this.startTime) {
706706
this.endTime = hrtime();
707707
}
708-
this.startTime ??= this.endTime;
709708

710709
// The test has run, so recursively cancel any outstanding subtests and
711710
// mark this test as failed if any subtests failed.

test/fixtures/test-runner/output/hooks_spec_reporter.snapshot

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
describe hooks - no subtests (*ms)
1313
before throws
14-
1
14+
1 (*ms)
1515
'test did not finish before its parent and was cancelled'
1616

17-
2
17+
2 (*ms)
1818
'test did not finish before its parent and was cancelled'
1919

2020
before throws (*ms)
@@ -390,7 +390,7 @@
390390

391391
- after() called
392392
run after when before throws
393-
1
393+
1 (*ms)
394394
'test did not finish before its parent and was cancelled'
395395

396396
run after when before throws (*ms)
@@ -422,11 +422,11 @@
422422
failing tests:
423423

424424
*
425-
1
425+
1 (*ms)
426426
'test did not finish before its parent and was cancelled'
427427

428428
*
429-
2
429+
2 (*ms)
430430
'test did not finish before its parent and was cancelled'
431431

432432
*
@@ -772,7 +772,7 @@
772772
*
773773

774774
*
775-
1
775+
1 (*ms)
776776
'test did not finish before its parent and was cancelled'
777777

778778
*

0 commit comments

Comments
 (0)