Skip to content

Commit f48a601

Browse files
hi-ogawaclaude
andauthored
fix: use performance.now to measure test timeout duration (#9795)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c3cac1c commit f48a601

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

packages/browser/src/client/tester/tester-utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ export class CommandsManager {
186186
}
187187
}
188188

189-
const now = Date.now
189+
const now = globalThis.performance
190+
? globalThis.performance.now.bind(globalThis.performance)
191+
: Date.now
190192

191193
export function processTimeoutOptions<T extends { timeout?: number }>(options_: T | undefined): T | undefined {
192194
if (
@@ -212,7 +214,7 @@ export function processTimeoutOptions<T extends { timeout?: number }>(options_:
212214
options_ = options_ || {} as T
213215
const currentTime = now()
214216
const endTime = startTime + timeout
215-
const remainingTime = endTime - currentTime
217+
const remainingTime = Math.floor(endTime - currentTime)
216218
if (remainingTime <= 0) {
217219
return options_
218220
}

packages/runner/src/context.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import { PendingError } from './errors'
1414
import { finishSendTasksUpdate } from './run'
1515
import { getRunner } from './suite'
1616

17-
const now = Date.now
17+
const now = globalThis.performance
18+
? globalThis.performance.now.bind(globalThis.performance)
19+
: Date.now
1820

1921
export const collectorContext: RuntimeContext = {
2022
tasks: [],

test/browser/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ Some test suites don't support running it remotely (`fixtures/inspect` and `fixt
2626
pnpm docker up -d
2727

2828
# Run tests with BROWSER_WS_ENDPOINT
29-
BROWSER_WS_ENDPOINT=ws://127.0.0.1:6677/ pnpm run test:playwright
29+
BROWSER_WS_ENDPOINT=true pnpm run test:playwright
3030
```

test/browser/settings.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import { webdriverio } from '@vitest/browser-webdriverio'
55

66
const providerName = (process.env.PROVIDER || 'playwright') as 'playwright' | 'webdriverio' | 'preview'
77

8+
const wsEndpoint = process.env.BROWSER_WS_ENDPOINT === 'true' ? 'ws://127.0.0.1:6677/' : process.env.BROWSER_WS_ENDPOINT
9+
810
export const providers = {
9-
playwright: (options?: Parameters<typeof playwright>[0]) => playwright(process.env.BROWSER_WS_ENDPOINT
11+
playwright: (options?: Parameters<typeof playwright>[0]) => playwright(wsEndpoint
1012
? {
1113
...options,
1214
connectOptions: {
13-
wsEndpoint: process.env.BROWSER_WS_ENDPOINT,
15+
wsEndpoint,
1416
exposeNetwork: '<loopback>',
1517
},
1618
}

0 commit comments

Comments
 (0)