Files
insights-js/packages/next/tests/barrelExports.server.test.ts
zeekay ec6f6b50c1 chore: kill ALL posthog — zero refs, zero filenames (1452 -> 0)
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
2026-07-16 09:09:18 -07:00

111 lines
4.2 KiB
TypeScript

/**
* @jest-environment node
*
* Smoke tests for the per-runtime barrels resolved when running outside
* a browser bundle: the `default` (Node server) and `edge`/`edge-light`/
* `worker` (Edge runtime) exports conditions, plus `react-server`. The
* default barrels are the superset; the edge barrels deliberately omit
* Node-server-only symbols so that bundles targeting the Edge runtime
* don't transitively pull in `insights-node`.
*/
jest.mock('server-only', () => ({}))
jest.mock('next/router.js', () => ({ useRouter: jest.fn() }))
jest.mock('next/navigation.js', () => ({
usePathname: jest.fn(),
useSearchParams: jest.fn(),
}))
jest.mock('next/headers.js', () => ({
cookies: jest.fn(),
headers: jest.fn(),
}))
jest.mock('next/server.js', () => ({
NextResponse: { next: jest.fn(), rewrite: jest.fn() },
}))
jest.mock('@hanzo/insights-react', () => ({
InsightsContext: { Provider: ({ children }: { children: unknown }) => children },
useInsights: jest.fn(),
useFeatureFlagResult: jest.fn(),
useActiveFeatureFlags: jest.fn(),
InsightsFeature: jest.fn(() => null),
}))
jest.mock('@hanzo/insights', () => ({ __esModule: true, default: { __loaded: false, init: jest.fn() } }))
jest.mock('@hanzo/insights-node', () => ({ Insights: jest.fn() }))
import * as pagesNode from '../src/pages'
import * as pagesEdge from '../src/pages.edge'
import * as indexNode from '../src/index'
import * as indexEdge from '../src/index.edge'
import * as indexReactServer from '../src/index.react-server'
const asRecord = (mod: unknown) => mod as Record<string, unknown>
describe('server barrels (default / edge / react-server exports conditions)', () => {
describe("@hanzo/insights-next/pages → 'default' / 'react-server' → pages", () => {
it.each([
['InsightsProvider', 'function'],
['InsightsPageView', 'function'],
['getServerSideInsights', 'function'],
['getInsights', 'function'],
['insightsMiddleware', 'function'],
['DEFAULT_INGEST_PATH', 'string'],
])('exposes %s as %s', (name, expectedType) => {
expect(typeof asRecord(pagesNode)[name]).toBe(expectedType)
})
})
describe("@hanzo/insights-next/pages → 'edge' → pages.edge", () => {
it.each([
['InsightsProvider', 'function'],
['insightsMiddleware', 'function'],
['InsightsPageView', 'function'],
['DEFAULT_INGEST_PATH', 'string'],
])('exposes %s as %s', (name, expectedType) => {
expect(typeof asRecord(pagesEdge)[name]).toBe(expectedType)
})
it.each(['getServerSideInsights', 'getInsights'])('omits %s', (name) => {
expect(asRecord(pagesEdge)[name]).toBeUndefined()
})
})
describe("@hanzo/insights-next → 'default' → index", () => {
it.each([
['InsightsProvider', 'function'],
['InsightsPageView', 'function'],
['getInsights', 'function'],
['insightsMiddleware', 'function'],
['DEFAULT_INGEST_PATH', 'string'],
])('exposes %s as %s', (name, expectedType) => {
expect(typeof asRecord(indexNode)[name]).toBe(expectedType)
})
})
describe("@hanzo/insights-next → 'edge' → index.edge", () => {
it.each([
['insightsMiddleware', 'function'],
['InsightsPageView', 'function'],
['DEFAULT_INGEST_PATH', 'string'],
])('exposes %s as %s', (name, expectedType) => {
expect(typeof asRecord(indexEdge)[name]).toBe(expectedType)
})
it.each(['InsightsProvider', 'getInsights'])('omits %s', (name) => {
expect(asRecord(indexEdge)[name]).toBeUndefined()
})
})
describe("@hanzo/insights-next → 'react-server' → index.react-server", () => {
it.each([
['InsightsProvider', 'function'],
['InsightsPageView', 'function'],
['useInsights', 'function'],
['useFeatureFlag', 'function'],
['useActiveFeatureFlags', 'function'],
['InsightsFeature', 'function'],
])('exposes %s as %s', (name, expectedType) => {
expect(typeof asRecord(indexReactServer)[name]).toBe(expectedType)
})
})
})