fix: add global CRM services mock to prevent test flakes#26716
Merged
anikdhabal merged 3 commits intomainfrom Jan 11, 2026
Merged
fix: add global CRM services mock to prevent test flakes#26716anikdhabal merged 3 commits intomainfrom
anikdhabal merged 3 commits intomainfrom
Conversation
….test.ts Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
The test flakes were caused by the Salesforce CRM service importing @urql/core, which triggers fetch calls during module loading. These fetch calls remain pending when the Vitest worker shuts down, causing the error: '[vitest-worker]: Closing rpc while fetch was pending' This fix adds a global mock for CrmServiceMap in setupVitest.ts, similar to how payment services are already mocked. This prevents the Salesforce module from being loaded during test execution. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
anikdhabal
approved these changes
Jan 11, 2026
Anshumancanrock
pushed a commit
to Anshumancanrock/cal.com
that referenced
this pull request
Jan 12, 2026
* fix: mock CRM services to prevent test flakes in handlePaymentSuccess.test.ts Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: add global CRM services mock to prevent test flakes The test flakes were caused by the Salesforce CRM service importing @urql/core, which triggers fetch calls during module loading. These fetch calls remain pending when the Vitest worker shuts down, causing the error: '[vitest-worker]: Closing rpc while fetch was pending' This fix adds a global mock for CrmServiceMap in setupVitest.ts, similar to how payment services are already mocked. This prevents the Salesforce module from being loaded during test execution. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
What does this PR do?
Fixes flaky unit test failures caused by pending fetch requests during test teardown. Multiple tests were intermittently failing with the error:
Root cause: The import chain through
EventManager→CrmManager→getCrm→crm.apps.generatedloads the Salesforce CRM service, which imports@urql/core. This GraphQL client library can trigger fetch calls that remain pending when the Vitest worker shuts down. The error message shows whichever module was being loaded at shutdown time (e.g., routing-forms, watchlist), but the actual culprit is the Salesforce GraphQL client.Fix: Add a global mock for
CrmServiceMapinsetupVitest.ts(similar to how payment services are already mocked). This prevents all CRM modules from being loaded during test execution, fixing the flakiness across all affected tests.Changes
MockCrmServiceclass insetupVitest.tswith stub implementations@calcom/app-store/crm.apps.generatedcovering all CRM integrations (closecom, hubspot, pipedrive-crm, salesforce, zoho-bigin, zohocrm)handlePaymentSuccess.test.tsMandatory Tasks (DO NOT REMOVE)
How should this be tested?
TZ=UTC yarn test packages/app-store/_utils/payments/handlePaymentSuccess.test.tsTZ=UTC yarn testLocal verification completed:
Human Review Checklist
Promise.resolve({ default: MockCrmService })) matches the dynamic import pattern used incrm.apps.generated.ts!process.env.INTEGRATION_TESTScheckChecklist
Requested by: @keithwillcode
Link to Devin run: https://app.devin.ai/sessions/94298285724d485caebcd8e8b39beab4