Skip to content

Commit ba3b2d2

Browse files
cjihrigrdw-msft
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: nodejs#52182 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 526b3b5 commit ba3b2d2

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lib/internal/test_runner/test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ class Test extends AsyncResource {
507507
}
508508

509509
if (preventAddingSubtests) {
510-
test.startTime = test.startTime || hrtime();
511510
test.fail(
512511
new ERR_TEST_FAILURE(
513512
'test could not be started because its parent finished',
@@ -537,7 +536,6 @@ class Test extends AsyncResource {
537536
kCancelledByParent,
538537
),
539538
);
540-
this.startTime = this.startTime || this.endTime; // If a test was canceled before it was started, e.g inside a hook
541539
this.cancelled = true;
542540
this.abortController.abort();
543541
}
@@ -763,12 +761,13 @@ class Test extends AsyncResource {
763761
}
764762

765763
postRun(pendingSubtestsError) {
764+
this.startTime ??= hrtime();
765+
766766
// If the test was failed before it even started, then the end time will
767767
// be earlier than the start time. Correct that here.
768768
if (this.endTime < this.startTime) {
769769
this.endTime = hrtime();
770770
}
771-
this.startTime ??= this.endTime;
772771

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

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

+6-6
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)