Skip to content

Commit a4f7f4f

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 9069c95 commit a4f7f4f

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
@@ -479,7 +479,6 @@ class Test extends AsyncResource {
479479
}
480480

481481
if (preventAddingSubtests) {
482-
test.startTime = test.startTime || hrtime();
483482
test.fail(
484483
new ERR_TEST_FAILURE(
485484
'test could not be started because its parent finished',
@@ -509,7 +508,6 @@ class Test extends AsyncResource {
509508
kCancelledByParent,
510509
),
511510
);
512-
this.startTime = this.startTime || this.endTime; // If a test was canceled before it was started, e.g inside a hook
513511
this.cancelled = true;
514512
this.abortController.abort();
515513
}
@@ -735,12 +733,13 @@ class Test extends AsyncResource {
735733
}
736734

737735
postRun(pendingSubtestsError) {
736+
this.startTime ??= hrtime();
737+
738738
// If the test was failed before it even started, then the end time will
739739
// be earlier than the start time. Correct that here.
740740
if (this.endTime < this.startTime) {
741741
this.endTime = hrtime();
742742
}
743-
this.startTime ??= this.endTime;
744743

745744
// The test has run, so recursively cancel any outstanding subtests and
746745
// 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)