diff --git a/lib/error-reporting/__tests__/client-lite.test.ts b/lib/error-reporting/__tests__/client-lite.test.ts index 3c6064839..5e4ab5d04 100644 --- a/lib/error-reporting/__tests__/client-lite.test.ts +++ b/lib/error-reporting/__tests__/client-lite.test.ts @@ -1,16 +1,12 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -vi.mock('@/lib/lite', async (importOriginal) => ({ - ...(await importOriginal()), - IS_LITE: true, -})); - import { captureException, configureErrorReporting, resetErrorReportingForTests } from '../client'; const DSN = 'https://6f0b9c79ed3a4315b76595bc2536ac40@bugsink.example.org/3'; let fetchSpy: ReturnType; beforeEach(() => { + vi.stubEnv('NEXT_PUBLIC_BULWARK_LITE', '1'); resetErrorReportingForTests(); sessionStorage.clear(); fetchSpy = vi.fn().mockResolvedValue(new Response(null, { status: 200 })); @@ -18,6 +14,7 @@ beforeEach(() => { }); afterEach(() => { + vi.unstubAllEnvs(); vi.unstubAllGlobals(); }); diff --git a/lib/error-reporting/client.ts b/lib/error-reporting/client.ts index 712a21f14..23d6e69db 100644 --- a/lib/error-reporting/client.ts +++ b/lib/error-reporting/client.ts @@ -1,5 +1,4 @@ import { apiFetch, getPathPrefix } from '@/lib/browser-navigation'; -import { IS_LITE } from '@/lib/lite'; import { scrubRoutePath } from '@/lib/route-groups'; import { debugIdsByPath } from './debug-ids'; import { @@ -201,9 +200,10 @@ function deliver(report: ErrorReport): void { mode: 'cors', }); } - // Lite has no server: the bundler drops this branch, and the endpoint - // with it (scripts/lite/verify.mjs fails on undocumented /api strings). - if (!IS_LITE && settings.collect) { + // Lite has no server. Read here, not through IS_LITE: the bundler inlines + // the variable only in this module, so the branch and the endpoint string + // leave the Lite bundle (scripts/lite/verify.mjs). + if (process.env.NEXT_PUBLIC_BULWARK_LITE !== '1' && settings.collect) { send('/api/errors', JSON.stringify({ name: report.name, message: report.message,