diff --git a/.babelrc b/.babelrc index 7fe9a63a1..b61790df4 100644 --- a/.babelrc +++ b/.babelrc @@ -1,13 +1,26 @@ { - "presets": ["@babel/env", ["@babel/typescript", { "jsxPragma": "h" }]], - "plugins": [ - "@babel/plugin-transform-nullish-coalescing-operator", - [ - "@babel/transform-react-jsx", - { - "runtime": "automatic", - "importSource": "preact" - } - ] + "presets": [ + [ + "@babel/env", + { + "targets": ">0.5%, last 2 versions, Firefox ESR, not dead" + } + ], + [ + "@babel/typescript", + { + "jsxPragma": "h" + } ] + ], + "plugins": [ + "@babel/plugin-transform-nullish-coalescing-operator", + [ + "@babel/transform-react-jsx", + { + "runtime": "automatic", + "importSource": "preact" + } + ] + ] } diff --git a/src/__tests__/posthog-core.test.ts b/src/__tests__/posthog-core.test.ts index 7b8047c56..69f7154ec 100644 --- a/src/__tests__/posthog-core.test.ts +++ b/src/__tests__/posthog-core.test.ts @@ -1,9 +1,9 @@ -import { defaultPostHog } from './helpers/posthog-instance' +const mockReferrerGetter = jest.fn() +const mockURLGetter = jest.fn() + import type { PostHogConfig } from '../types' import { uuidv7 } from '../uuidv7' -const mockReferrerGetter = jest.fn() -const mockURLGetter = jest.fn() jest.mock('../utils/globals', () => { const orig = jest.requireActual('../utils/globals') return { @@ -29,7 +29,13 @@ jest.mock('../utils/globals', () => { }) describe('posthog core', () => { - beforeEach(() => { + let defaultPostHog: typeof import('./helpers/posthog-instance').defaultPostHog + beforeEach(async () => { + // delay the import to ensure the mocks are set up before being accessed + // @ts-expect-error - allow dynamic imports + const posthogModule = await import('./helpers/posthog-instance') + defaultPostHog = posthogModule.defaultPostHog + mockReferrerGetter.mockReturnValue('https://referrer.com') mockURLGetter.mockReturnValue('https://example.com') console.error = jest.fn()