(
killFn: (ctx: TestContext) => void,
spawnOptions?: SpawnOptions,
)
| 159 | |
| 160 | describe('Telemetry E2E', () => { |
| 161 | async function runTelemetryTest( |
| 162 | killFn: (ctx: TestContext) => void, |
| 163 | spawnOptions?: SpawnOptions, |
| 164 | ): Promise<void> { |
| 165 | const mockContext = await startMockServer(); |
| 166 | const ctx: TestContext = { |
| 167 | mockServer: mockContext, |
| 168 | }; |
| 169 | |
| 170 | try { |
| 171 | ctx.process = spawn( |
| 172 | process.execPath, |
| 173 | [ |
| 174 | SERVER_PATH, |
| 175 | '--usage-statistics', |
| 176 | '--headless', |
| 177 | `--clearcutEndpoint=http://127.0.0.1:${mockContext.port}`, |
| 178 | '--clearcutForceFlushIntervalMs=10', |
| 179 | '--clearcutIncludePidHeader', |
| 180 | ], |
| 181 | { |
| 182 | stdio: ['pipe', 'pipe', 'pipe'], |
| 183 | env: { |
| 184 | ...process.env, |
| 185 | CI: undefined, |
| 186 | CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS: undefined, |
| 187 | }, |
| 188 | ...spawnOptions, |
| 189 | }, |
| 190 | ); |
| 191 | |
| 192 | const startEvent = await Promise.race([ |
| 193 | mockContext.waitForEvent(e => e.server_start !== undefined), |
| 194 | new Promise((_, reject) => |
| 195 | setTimeout( |
| 196 | () => reject(new Error('Timeout waiting for server_start')), |
| 197 | 10000, |
| 198 | ), |
| 199 | ), |
| 200 | ]); |
| 201 | assert.ok(startEvent, 'server_start event not received'); |
| 202 | |
| 203 | // Now that we received an event, we should have the Watchdog PID |
| 204 | const watchdogPid = mockContext.watchdogPid; |
| 205 | assert.ok(watchdogPid, 'Watchdog PID not captured from headers'); |
| 206 | |
| 207 | // Assert Watchdog is actually running |
| 208 | assert.strictEqual( |
| 209 | isProcessAlive(watchdogPid), |
| 210 | true, |
| 211 | 'Watchdog process should be running', |
| 212 | ); |
| 213 | |
| 214 | // Trigger shutdown |
| 215 | killFn(ctx); |
| 216 | |
| 217 | // Verify shutdown event |
| 218 | const shutdownEvent = await Promise.race([ |
no test coverage detected