Skip to content

Commit

Permalink
perf(runner): Use globalThis.performance.now instead of Date.now
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan committed Aug 27, 2024
1 parent 83638eb commit d6da130
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/runner/src/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getHooks, setHooks } from './map'
import { collectorContext } from './context'
import { runSetupFiles } from './setup'

const now = Date.now
const now = globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now

export async function collectTests(
paths: string[],
Expand Down
7 changes: 4 additions & 3 deletions packages/runner/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { hasFailed, hasTests } from './utils/tasks'
import { PendingError } from './errors'
import { callFixtureCleanup } from './fixture'

const now = Date.now
const now = globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now
const unixNow = Date.now

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

test.result = {
state: 'run',
startTime: start,
startTime: unixNow(),
retryCount: 0,
}
updateTask(test, runner)
Expand Down Expand Up @@ -376,7 +377,7 @@ export async function runSuite(suite: Suite, runner: VitestRunner): Promise<void

suite.result = {
state: 'run',
startTime: start,
startTime: unixNow(),
}

updateTask(suite, runner)
Expand Down

0 comments on commit d6da130

Please sign in to comment.