Skip to content

fix: add global CRM services mock to prevent test flakes#26716

Merged
anikdhabal merged 3 commits intomainfrom
devin/fix-unit-test-flakes-1768125232
Jan 11, 2026
Merged

fix: add global CRM services mock to prevent test flakes#26716
anikdhabal merged 3 commits intomainfrom
devin/fix-unit-test-flakes-1768125232

Conversation

@keithwillcode
Copy link
Contributor

@keithwillcode keithwillcode commented Jan 11, 2026

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:

[vitest-worker]: Closing rpc while "fetch" was pending

Root cause: The import chain through EventManagerCrmManagergetCrmcrm.apps.generated loads 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 CrmServiceMap in setupVitest.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

  • Added MockCrmService class in setupVitest.ts with stub implementations
  • Added global mock for @calcom/app-store/crm.apps.generated covering all CRM integrations (closecom, hubspot, pipedrive-crm, salesforce, zoho-bigin, zohocrm)
  • Removed redundant comment in handlePaymentSuccess.test.ts

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A - test infrastructure change only.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  1. Run the unit tests: TZ=UTC yarn test packages/app-store/_utils/payments/handlePaymentSuccess.test.ts
  2. Run the full unit test suite multiple times to verify no flakiness: TZ=UTC yarn test
  3. Verify CI passes without the "Closing rpc while fetch was pending" error

Local verification completed:

  • All 407 app-store tests pass
  • All 529 bookings tests pass (including EventManager.test.ts)

Human Review Checklist

  • Verify the mock structure (Promise.resolve({ default: MockCrmService })) matches the dynamic import pattern used in crm.apps.generated.ts
  • Confirm no existing tests rely on actual CRM service behavior that would be broken by this mock
  • Note: Integration tests are excluded from this mock via the existing !process.env.INTEGRATION_TESTS check

Checklist

  • My code follows the style guidelines of this project
  • I have checked if my changes generate no new warnings

Requested by: @keithwillcode
Link to Devin run: https://app.devin.ai/sessions/94298285724d485caebcd8e8b39beab4

….test.ts

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@keithwillcode keithwillcode self-assigned this Jan 11, 2026
@keithwillcode keithwillcode added this to the v6.1 milestone Jan 11, 2026
@keithwillcode keithwillcode marked this pull request as ready for review January 11, 2026 09:58
@graphite-app graphite-app bot added foundation core area: core, team members only labels Jan 11, 2026
@graphite-app graphite-app bot requested a review from a team January 11, 2026 09:59
@keithwillcode keithwillcode changed the title fix: mock CRM services to prevent test flakes in handlePaymentSuccess.test.ts test: mock CRM services to prevent test flakes in handlePaymentSuccess.test.ts Jan 11, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

keithwillcode and others added 2 commits January 11, 2026 07:28
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>
@devin-ai-integration devin-ai-integration bot changed the title test: mock CRM services to prevent test flakes in handlePaymentSuccess.test.ts fix: add global CRM services mock to prevent test flakes Jan 11, 2026
@anikdhabal anikdhabal merged commit 7a6f4b2 into main Jan 11, 2026
51 of 52 checks passed
@anikdhabal anikdhabal deleted the devin/fix-unit-test-flakes-1768125232 branch January 11, 2026 12:48
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>
@vercel vercel bot temporarily deployed to Preview – cal-companion January 13, 2026 08:36 Inactive
@vercel vercel bot temporarily deployed to Preview – dev January 13, 2026 08:36 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants