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

Function preOptimizeDevServer

e2e/e2e-utils/src/devServerWarmup.ts:32–69  ·  view source on GitHub ↗
(opts: {
  baseURL: string
  readyTestId?: string
  warmup?: (page: Page) => Promise<void>
})

Source from the content-addressed store, hash-verified

30}
31
32export async function preOptimizeDevServer(opts: {
33 baseURL: string
34 readyTestId?: string
35 warmup?: (page: Page) => Promise<void>
36}) {
37 const browser = await chromium.launch()
38 const context = await browser.newContext()
39 const page = await context.newPage()
40
41 try {
42 await page.goto(`${opts.baseURL}/`, { waitUntil: 'domcontentloaded' })
43
44 if (opts.readyTestId) {
45 await page.getByTestId(opts.readyTestId).waitFor({ state: 'visible' })
46 }
47
48 await page.waitForLoadState('networkidle')
49
50 await opts.warmup?.(page)
51
52 for (let i = 0; i < 40; i++) {
53 const currentUrl = page.url()
54 await page.waitForTimeout(250)
55
56 if (page.url() === currentUrl) {
57 await page.waitForTimeout(250)
58 if (page.url() === currentUrl) {
59 return
60 }
61 }
62 }
63
64 throw new Error('Dev server did not reach a stable URL after warmup')
65 } finally {
66 await context.close()
67 await browser.close()
68 }
69}

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 1

closeMethod · 0.65

Tested by

no test coverage detected