MCPcopy Create free account
hub / github.com/TanStack/router / waitForServer

Function waitForServer

e2e/e2e-utils/src/devServerWarmup.ts:4–30  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

2import type { Page } from '@playwright/test'
3
4export async function waitForServer(url: string) {
5 const start = Date.now()
6
7 while (Date.now() - start < 30_000) {
8 const controller = new AbortController()
9 const timer = setTimeout(() => controller.abort(), 5_000)
10
11 try {
12 const res = await fetch(url, {
13 redirect: 'manual',
14 signal: controller.signal,
15 })
16
17 if (res.status >= 200 && res.status < 400) {
18 return
19 }
20 } catch {
21 // ignore aborted/network errors
22 } finally {
23 clearTimeout(timer)
24 }
25
26 await new Promise((resolve) => setTimeout(resolve, 250))
27 }
28
29 throw new Error(`Timed out waiting for dev server at ${url}`)
30}
31
32export async function preOptimizeDevServer(opts: {
33 baseURL: string

Callers 8

setupFunction · 0.85
setupFunction · 0.85
setupFunction · 0.85
setupFunction · 0.85
setupFunction · 0.85
setupFunction · 0.85
setupFunction · 0.85
setupFunction · 0.85

Calls 2

abortMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected