-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_runner: avoid overwriting root start time
This commit ensures the root test start time is not overwritten when top level before()/after() hooks are run. PR-URL: #52020 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
- Loading branch information
Showing
3 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { test, after } from 'node:test'; | ||
|
||
after(() => {}); | ||
|
||
test('a test with some delay', (t, done) => { | ||
setTimeout(done, 50); | ||
}); |
This file contains 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 |
---|---|---|
@@ -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); | ||
}); |