MCPcopy Create free account
hub / github.com/TanStack/ai / waitForResponse

Function waitForResponse

testing/panel/tests/helpers.ts:106–155  ·  view source on GitHub ↗
(
  page: Page,
  timeout: number = 60_000,
)

Source from the content-addressed store, hash-verified

104 * Wait for the assistant response to complete
105 */
106export async function waitForResponse(
107 page: Page,
108 timeout: number = 60_000,
109): Promise<void> {
110 // Wait for loading to start - the stop button should appear or we see loading indicator
111 const stopButton = page.locator('button:has-text("Stop")')
112
113 // First, wait a moment for loading to potentially start
114 await page.waitForTimeout(1000)
115
116 // Check if loading started by looking for the stop button
117 const loadingStarted = await stopButton.isVisible().catch(() => false)
118
119 if (loadingStarted) {
120 // Wait for loading to complete (stop button to disappear)
121 try {
122 await stopButton.waitFor({ state: 'hidden', timeout: timeout - 1000 })
123 } catch {
124 // Stop button might still be visible if test times out
125 }
126 } else {
127 // Loading might have been too fast or there's an error
128 // Wait for either an assistant message or an error to appear
129 const messagesJson = page
130 .locator('pre')
131 .filter({ hasText: '"role"' })
132 .first()
133 try {
134 // Wait for the messages JSON to contain an assistant message
135 await page.waitForFunction(
136 () => {
137 const preElements = document.querySelectorAll('pre')
138 for (const pre of preElements) {
139 const text = pre.textContent || ''
140 if (text.includes('"assistant"')) {
141 return true
142 }
143 }
144 return false
145 },
146 { timeout: timeout - 1000 },
147 )
148 } catch {
149 // Timeout waiting for response
150 }
151 }
152
153 // Additional wait for message to fully render
154 await page.waitForTimeout(500)
155}
156
157/**
158 * Get the last assistant message text from the chat

Callers 2

tool-flow.spec.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected