(options: DevServerOptions, expectFailure?: boolean)
| 243 | } |
| 244 | |
| 245 | export const startDevServer = async (options: DevServerOptions, expectFailure?: boolean): Promise<DevServer> => { |
| 246 | const maxAttempts = 5 |
| 247 | |
| 248 | for (let attempt = 1; attempt <= maxAttempts; attempt++) { |
| 249 | try { |
| 250 | // do not use destruction, as we use getters which otherwise would be evaluated here |
| 251 | const devServer = await startServer({ ...options, expectFailure }) |
| 252 | if ('timeout' in devServer && devServer.timeout) { |
| 253 | throw new Error( |
| 254 | `Timed out starting dev server.\nServer Output:\n${devServer.output}\nServer Error:\n${ |
| 255 | devServer.error ?? '' |
| 256 | }\nDiagnostic Report:\n${devServer.report ?? '(none captured)'}`, |
| 257 | ) |
| 258 | } |
| 259 | return devServer as DevServer |
| 260 | } catch (error) { |
| 261 | if (attempt === maxAttempts || expectFailure) { |
| 262 | throw error |
| 263 | } |
| 264 | console.warn('Retrying startDevServer', error) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | throw new Error('this code should be unreachable') |
| 269 | } |
| 270 | |
| 271 | export const withDevServer = async <T>( |
| 272 | options: DevServerOptions, |
no test coverage detected