MCPcopy Create free account
hub / github.com/TanStack/cli / getCapturedEvent

Function getCapturedEvent

packages/cli/tests/telemetry.test.ts:17–42  ·  view source on GitHub ↗
(index: number)

Source from the content-addressed store, hash-verified

15const TELEMETRY_TRANSPORT_PATH = '/g/collect'
16
17function 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
44describe('telemetry', () => {
45 const originalCI = process.env.CI

Callers 1

telemetry.test.tsFile · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected