(command: string, url: string, cwd: string)
| 92 | }; |
| 93 | |
| 94 | const startWebServer = async (command: string, url: string, cwd: string) => { |
| 95 | const output: string[] = []; |
| 96 | const appendOutput = (source: 'stdout' | 'stderr', chunk: Buffer) => { |
| 97 | output.push(`[${source}] ${chunk.toString()}`); |
| 98 | output.splice(0, Math.max(0, output.length - 40)); |
| 99 | }; |
| 100 | const formatOutput = () => |
| 101 | output.length === 0 |
| 102 | ? 'No server output was captured.' |
| 103 | : output.join('').trim(); |
| 104 | const child = child_process.spawn(command, { |
| 105 | shell: true, |
| 106 | cwd, |
| 107 | detached: process.platform !== 'win32', |
| 108 | stdio: ['ignore', 'pipe', 'pipe'], |
| 109 | }); |
| 110 | child.stdout?.on('data', (chunk) => appendOutput('stdout', chunk)); |
| 111 | child.stderr?.on('data', (chunk) => appendOutput('stderr', chunk)); |
| 112 | |
| 113 | const childExit = new Promise<never>((_, reject) => { |
| 114 | child.once('error', reject); |
| 115 | child.once('exit', (code, signal) => { |
| 116 | reject( |
| 117 | new Error( |
| 118 | `Command "${command}" exited before ${url} became available. Exit code: ${code}; signal: ${signal}.\n\n${formatOutput()}`, |
| 119 | ), |
| 120 | ); |
| 121 | }); |
| 122 | }); |
| 123 | |
| 124 | try { |
| 125 | await Promise.race([waitForServer(url, 30_000), childExit]); |
| 126 | } catch (error) { |
| 127 | stopWebServer(child); |
| 128 | if (error instanceof Error) { |
| 129 | throw new Error(`${error.message}\n\n${formatOutput()}`); |
| 130 | } |
| 131 | throw error; |
| 132 | } |
| 133 | |
| 134 | return child; |
| 135 | }; |
| 136 | |
| 137 | describe('integrations', () => { |
| 138 | let page!: playwright.Page; |
no test coverage detected
searching dependent graphs…