FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test_runner: simplify test time tracking by cjihrig · Pull Request #52182 · nodejs/node · GitHub

/ node Public
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
28 changes: 8 additions & 20 deletions lib/internal/test_runner/test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ class Test extends AsyncResource {
}

if (preventAddingSubtests) {
test.startTime = test.startTime || hrtime();
test.fail(
new ERR_TEST_FAILURE(
'test could not be started because its parent finished',
Expand All @@ -527,7 +526,7 @@ class Test extends AsyncResource {
};

#cancel(error) {
if (this.endTime !== null) {
if (this.endTime !== null || this.error !== null) {
return;
}

Expand All @@ -537,7 +536,6 @@ class Test extends AsyncResource {
kCancelledByParent,
),
);
this.startTime = this.startTime || this.endTime; // If a test was canceled before it was started, e.g inside a hook
this.cancelled = true;
this.abortController.abort();
}
Expand Down Expand Up @@ -566,17 +564,15 @@ class Test extends AsyncResource {
return;
}

this.endTime = hrtime();
this.passed = false;
this.error = err;
}

pass() {
if (this.endTime !== null) {
if (this.error !== null) {
return;
}

this.endTime = hrtime();
this.passed = true;
}

Expand Down Expand Up @@ -709,15 +705,8 @@ class Test extends AsyncResource {
}

this.pass();
try {
await afterEach();
await after();
} catch (err) {
// If one of the after hooks has thrown unset endTime so that the
// catch below can do its cancel/fail logic.
this.endTime = null;
throw err;
}
await afterEach();
await after();
} catch (err) {
if (isTestFailureError(err)) {
if (err.failureType === kTestTimeoutFailure) {
Expand Down Expand Up @@ -763,11 +752,9 @@ class Test extends AsyncResource {
}

postRun(pendingSubtestsError) {
// If the test was failed before it even started, then the end time will
// be earlier than the start time. Correct that here.
if (this.endTime < this.startTime) {
this.endTime = hrtime();
}
// If the test was cancelled before it started, then the start and end
// times need to be corrected.
this.endTime ??= hrtime();
this.startTime ??= this.endTime;

// The test has run, so recursively cancel any outstanding subtests and
Expand Down Expand Up @@ -975,6 +962,7 @@ class TestHook extends Test {
error.failureType = kHookFailure;
}

this.endTime ??= hrtime();
parent.reporter.fail(0, loc, parent.subtests.length + 1, loc.file, {
__proto__: null,
duration_ms: this.duration(),
Expand Down

Back | FazBrowse Home | New Git URL