Verify edge cases and input validation for tracking fallback#5399
Conversation
|
@realtushartyagi is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds Vitest coverage for trackUser edge cases, focusing on empty-username no-ops and runtime fallbacks between navigator.sendBeacon and fetch.
Changes:
- Introduces a new test suite validating empty input short-circuit behavior.
- Adds tests for server/headless execution safety (missing
window/navigator). - Adds tests for
sendBeaconabsence/failure andfetchfallback error handling.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| beforeEach(() => { | ||
| originalWindow = globalThis.window; | ||
| originalNavigator = globalThis.navigator; | ||
| originalFetch = globalThis.fetch; | ||
| originalBlob = globalThis.Blob; | ||
|
|
||
| globalThis.window = {} as unknown as typeof globalThis.window; | ||
| globalThis.navigator = { | ||
| sendBeacon: vi.fn().mockReturnValue(true), | ||
| } as unknown as typeof globalThis.navigator; | ||
| globalThis.fetch = vi.fn().mockResolvedValue({ ok: true }); |
| // Ensure Blob is polyfilled securely to prevent hydration or runtime errors in CI | ||
| if (typeof globalThis.Blob === 'undefined') { | ||
| globalThis.Blob = class Blob { | ||
| constructor( | ||
| public parts: string[], | ||
| public options: Record<string, string> | ||
| ) {} | ||
| } as unknown as typeof globalThis.Blob; | ||
| } |
| // Wait a tick to ensure async catch block executes cleanly | ||
| await new Promise(process.nextTick); |
Aamod-Dev
left a comment
There was a problem hiding this comment.
Thanks for adding the edge case coverage for the tracking fallback! Ensuring sendBeacon queuing failures properly route to the fetch API prevents silent telemetry loss, which is great.
Your test coverage is perfect. However, you will notice the CI pipeline is currently failing due to an unrelated divergence in lib/svg/themes.test.ts on the main branch.
To secure a green build, simply run git pull --rebase origin main and force push your branch. I'll be ready to approve once that runs!
Labels Applied:
level:beginner: Standard API fallback testing.type:testing: Edge case validation.quality:clean: Excellent isolation of network limits.mentor:Aamod007
d511419 to
b7bdd54
Compare
Aamod-Dev
left a comment
There was a problem hiding this comment.
Great job resolving the issues! The pipeline divergence is fixed and the code looks completely solid. Approved! 🎉
Aamod-Dev
left a comment
There was a problem hiding this comment.
Great job resolving the issues! The pipeline divergence is fixed and the code looks completely solid. Approved! 🎉
Aamod-Dev
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I went through the changes and the overall approach looks good.
|
🎉 Congratulations @realtushartyagi! Your PR has been successfully merged. 🚀 Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.
Keep building! 💻✨ |
Aamod-Dev
left a comment
There was a problem hiding this comment.
Looks great! I went through the changes and ensuring tracking edge cases are verified makes the telemetry pipeline much safer.
Labels applied:
- level:advanced: Complex input verification.
- quality:clean: Robust coverage.
- ype:feature: Feature telemetry testing.
Description
Fixes #4309
This PR Adds empty-input and fallback tests for utils/tracking.ts.
Pillar
Visual Preview
N/A (Integration Test update)
Checklist before requesting a review: