mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
We own the ingestion server (hanzoai/insights: Django + rust/capture + nodejs plugin) AND this SDK, so there is no external wire contract to preserve. The server is already 100% posthog-free; this SDK was the last laggard. - $last_posthog_reset -> $last_insights_reset. This FIXES A LIVE MISMATCH: the server taxonomy (insights/taxonomy/taxonomy.py, insights/insightsql/ai.py) already expected the insights form while the SDK emitted the posthog form. - __PosthogExtensions__ -> __InsightsExtensions__; all PostHog/posthog/POSTHOG identifiers -> Insights/insights/INSIGHTS (src, tests, playground, playwright, scripts, rrweb subpackages, package.json keywords). - Hosts: DEFAULT_PLUGIN_HOST + DEFAULT_NUXT_HOST + the core host default pointed at PostHog's cloud (us.i.posthog.com) — a real bug. All -> insights.hanzo.ai. - Removed the us-assets/eu-assets CDN split in getRemoteConfig (PostHog-specific; Hanzo serves remote config from the same host) — it had degenerated to a no-op. - Fixed generate-docs writing to a stray references/@hanzo/ subdir. - Renamed the 3 posthog-named test files; dropped 58MB of stale reference snapshots named for upstream posthog versions we never shipped (they are generated output — references/ is now gitignored). Verified: typecheck errors 42 (HEAD) -> 18 (all pre-existing test-mock looseness); types package 0; every package.json valid with @hanzo/* names. Guard: grep -rioE 'posthog' packages ... | wc -l => 0
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { Insights } from '../src'
|
|
import { isInsightsFetchNetworkError } from '@hanzo/insights-core'
|
|
|
|
// Proves the exported instanceof guard recognizes a genuine InsightsFetchNetworkError
|
|
// produced by core's real fetch path.
|
|
describe('isInsightsFetchNetworkError recognizes real core errors', () => {
|
|
const originalFetch = (globalThis as any).window.fetch
|
|
|
|
beforeAll(() => {
|
|
// The SDK flush/shutdown lifecycle is timer-driven; the suite's global fake timers
|
|
// would deadlock awaited async operations, so use real timers here.
|
|
jest.useRealTimers()
|
|
})
|
|
|
|
afterAll(() => {
|
|
;(globalThis as any).window.fetch = originalFetch
|
|
jest.useFakeTimers()
|
|
})
|
|
|
|
it('returns true for the error core throws when fetch fails', async () => {
|
|
;(globalThis as any).window.fetch = jest.fn(() => {
|
|
throw new Error('offline')
|
|
})
|
|
|
|
const insights = new Insights('test-token', {
|
|
persistence: 'memory',
|
|
flushInterval: 0,
|
|
fetchRetryCount: 0,
|
|
})
|
|
await insights.ready()
|
|
insights.capture('event')
|
|
|
|
let caught: unknown
|
|
try {
|
|
await insights.flush()
|
|
} catch (err) {
|
|
caught = err
|
|
}
|
|
await insights.shutdown()
|
|
|
|
expect(caught).toBeDefined()
|
|
expect(isInsightsFetchNetworkError(caught)).toBe(true)
|
|
// ordinary errors must not be mistaken for network errors
|
|
expect(isInsightsFetchNetworkError(new Error('boom'))).toBe(false)
|
|
}, 15000)
|
|
})
|