Skip to content

test(logger): cover logError DEV/PROD/Sentry branches - #201

Open
tanishxdev wants to merge 1 commit into
nastaso:mainfrom
tanishxdev:test-logger-branches
Open

test(logger): cover logError DEV/PROD/Sentry branches#201
tanishxdev wants to merge 1 commit into
nastaso:mainfrom
tanishxdev:test-logger-branches

Conversation

@tanishxdev

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds src/lib/logger.test.ts, unit-testing logError across all four DEV/PROD/Sentry code paths.

Why?

logError is the app's single error-logging chokepoint but had zero test coverage, so a regression here could silently swallow errors without anyone noticing.

Closes #51

How was this tested?

Added four cases in src/lib/logger.test.ts, following the style of src/lib/scoring.test.ts:

  • DEV: logs to console.error with the [context] prefix.
  • PROD + window.Sentry present: calls window.Sentry.captureException(err, { tags: { context } }).
  • PROD + Sentry throws: falls back to console.error (catch block), verified call order with toHaveBeenNthCalledWith.
  • PROD + no Sentry: logs to console.error.

window is stubbed per-test with vi.stubGlobal('window', {}) since the suite runs under environment: 'node' (per vitest.config.ts) with no real DOM global. import.meta.env.DEV/PROD are set directly as booleans (via a typed cast) rather than vi.stubEnv, since stubbing them as strings didn't coerce to real booleans in this setup and caused false-positive branch execution.

Ran locally:

Test Files  17 passed (17)
     Tests  225 passed (225)
  • npm run test — 225/225 passing (17 test files, including the new 4 in logger.test.ts)
  • npm run lint — clean, no errors or warnings
  • npm run validate — all question banks valid (pre-existing warnings in saa-c03 unrelated to this change)

Checklist

  • npm run build passes locally — could not fully verify; local build fails at static-path generation with Missing Supabase environment variables, unrelated to this change (no .env credentials configured locally)
  • npm run lint passes locally
  • npm run test passes locally
  • npm run validate passes locally (only if you touched src/data/**/*.json) — N/A, no data files touched (ran anyway, passes)
  • No new third-party dependencies

Screenshots (UI changes only)

N/A — test-only change, no UI impact.

@tanishxdev
tanishxdev requested a review from nastaso as a code owner July 13, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(logger): unit-test logError across DEV / PROD / Sentry paths

1 participant