| 15 | const TELEMETRY_TRANSPORT_PATH = '/g/collect' |
| 16 | |
| 17 | function getCapturedEvent(index: number) { |
| 18 | const mockedFetch = <typeof fetch & { |
| 19 | mock: { calls: Array<Array<unknown>> } |
| 20 | }>fetch |
| 21 | const requestUrl = String(mockedFetch.mock.calls[index]?.[0]) |
| 22 | const requestInit = <RequestInit | undefined>mockedFetch.mock.calls[index]?.[1] |
| 23 | const params = new URLSearchParams(String(requestInit?.body || '')) |
| 24 | |
| 25 | const properties: Record<string, string | number> = {} |
| 26 | for (const [key, value] of params.entries()) { |
| 27 | if (key.startsWith(TELEMETRY_NUMERIC_PREFIX)) { |
| 28 | properties[key.slice(TELEMETRY_NUMERIC_PREFIX.length)] = Number(value) |
| 29 | continue |
| 30 | } |
| 31 | |
| 32 | if (key.startsWith(TELEMETRY_STRING_PREFIX)) { |
| 33 | properties[key.slice(TELEMETRY_STRING_PREFIX.length)] = value |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return { |
| 38 | event: params.get('en'), |
| 39 | properties, |
| 40 | url: requestUrl, |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | describe('telemetry', () => { |
| 45 | const originalCI = process.env.CI |