Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: avoid overwriting root start time #52020

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ class Test extends AsyncResource {
if (this.parent !== null) {
this.parent.activeSubtests++;
}
this.startTime = hrtime();
this.startTime ??= hrtime();

if (this[kShouldAbort]()) {
this.postRun();
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/test-runner/root-duration.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test, after } from 'node:test';

after(() => {});

test('a test with some delay', (t, done) => {
setTimeout(done, 50);
});
25 changes: 25 additions & 0 deletions test/parallel/test-runner-root-duration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
const { spawnPromisified } = require('../common');
const fixtures = require('../common/fixtures');
const { strictEqual } = require('node:assert');
const { test } = require('node:test');

test('root duration is longer than test duration', async () => {
const {
code,
stderr,
stdout,
} = await spawnPromisified(process.execPath, [
fixtures.path('test-runner/root-duration.mjs'),
]);

strictEqual(code, 0);
strictEqual(stderr, '');
const durations = [...stdout.matchAll(/duration_ms:? ([.\d]+)/g)];
strictEqual(durations.length, 2);
const testDuration = Number.parseFloat(durations[0][1]);
const rootDuration = Number.parseFloat(durations[1][1]);
strictEqual(Number.isNaN(testDuration), false);
strictEqual(Number.isNaN(rootDuration), false);
strictEqual(rootDuration >= testDuration, true);
});
Loading