test: stop unit tests from sending events to production PostHog - #1373
Draft
posthog[bot] wants to merge 1 commit into
Draft
posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
Mock posthog-node in a global vitest setup file, so the analytics singleton and other clients never reach production error tracking from a test run. The real client's exception autocapture hid an unhandled rejection in the pi check_env_keys test. The test now handles the promise it creates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Generated-By: PostHog Desktop Task-Id: bcd9fae6-64f8-45bc-9515-41ba7a7bf497
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Test against a Context Mill branch:
Add Results will be posted here when complete. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
src/shared/utils/analytics.tsbuilds a realposthog-nodeclient with the production write key.debug.test.ts"blocker" test fails a log write on purpose.reportLogFailureOncethen callsanalytics.captureException, and the real client files anEEXISTissue.captureExceptioncalls.Origin
2595fc0Changes
vitest.setup.tsautomocksposthog-node.vitest.config.tsloads it for every test project. Explicit captures and autocaptured exceptions both go through that client, so both paths stop.vi.mock('posthog-node')(for example inanalytics.test.ts) still works as before.pi/__tests__/tools.test.ts: the test created a rejected promise and did not handle it. The real client'sunhandledRejectionlistener hid this from vitest. With the mock, vitest reports it, so the test now awaits the promise that it creates.Note
Any future test that leaves an unhandled rejection now fails the run. Before this change, the real client hid it and sent it to error tracking.
Test plan
pnpm test: 204 files, 3434 tests pass, no unhandled errors.pnpm typecheck, and eslint + prettier on the changed files.LLM context
posthog-nodemock over a mock of./analyticsindebug.test.tsonly, because the leak comes from many test files.Created with PostHog Desktop from this inbox report.
🤖 Generated with Claude Code