Skip to content

Commit fe48943

Browse files
authored
fix(runner): Use performance.now instead of Date.now for duration (#6382)
1 parent 83638eb commit fe48943

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

packages/runner/src/collect.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getHooks, setHooks } from './map'
1717
import { collectorContext } from './context'
1818
import { runSetupFiles } from './setup'
1919

20-
const now = Date.now
20+
const now = globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now
2121

2222
export async function collectTests(
2323
paths: string[],

packages/runner/src/run.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import { hasFailed, hasTests } from './utils/tasks'
2727
import { PendingError } from './errors'
2828
import { callFixtureCleanup } from './fixture'
2929

30-
const now = Date.now
30+
const now = globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now
31+
const unixNow = Date.now
3132

3233
function updateSuiteHookState(
3334
suite: Task,
@@ -181,7 +182,7 @@ export async function runTest(test: Test | Custom, runner: VitestRunner): Promis
181182

182183
test.result = {
183184
state: 'run',
184-
startTime: start,
185+
startTime: unixNow(),
185186
retryCount: 0,
186187
}
187188
updateTask(test, runner)
@@ -376,7 +377,7 @@ export async function runSuite(suite: Suite, runner: VitestRunner): Promise<void
376377

377378
suite.result = {
378379
state: 'run',
379-
startTime: start,
380+
startTime: unixNow(),
380381
}
381382

382383
updateTask(suite, runner)

0 commit comments

Comments
 (0)