From 7a6f4b259484d0d67e1bdab7c969092c363b38a3 Mon Sep 17 00:00:00 2001 From: Keith Williams Date: Sun, 11 Jan 2026 09:48:05 -0300 Subject: [PATCH] fix: add global CRM services mock to prevent test flakes (#26716) * 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> --- .../payments/handlePaymentSuccess.test.ts | 1 - packages/testing/src/setupVitest.ts | 28 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/app-store/_utils/payments/handlePaymentSuccess.test.ts b/packages/app-store/_utils/payments/handlePaymentSuccess.test.ts index 3faf859321..79485ee694 100644 --- a/packages/app-store/_utils/payments/handlePaymentSuccess.test.ts +++ b/packages/app-store/_utils/payments/handlePaymentSuccess.test.ts @@ -74,7 +74,6 @@ vi.mock("@calcom/lib/logger", () => ({ })), }, })); -// Mock routing-forms modules to prevent async import issues during test teardown vi.mock("@calcom/features/routing-forms/lib/findFieldValueByIdentifier", () => ({ findFieldValueByIdentifier: vi.fn(), })); diff --git a/packages/testing/src/setupVitest.ts b/packages/testing/src/setupVitest.ts index 350556b26e..1040d165a9 100644 --- a/packages/testing/src/setupVitest.ts +++ b/packages/testing/src/setupVitest.ts @@ -162,6 +162,34 @@ vi.mock("@calcom/app-store/payment.services.generated", () => ({ }, })); +class MockCrmService { + constructor() {} + async createEvent() { + return []; + } + async updateEvent() { + return []; + } + async deleteEvent() {} + async getContacts() { + return []; + } + async createContacts() { + return []; + } +} + +vi.mock("@calcom/app-store/crm.apps.generated", () => ({ + CrmServiceMap: { + closecom: Promise.resolve({ default: MockCrmService }), + hubspot: Promise.resolve({ default: MockCrmService }), + "pipedrive-crm": Promise.resolve({ default: MockCrmService }), + salesforce: Promise.resolve({ default: MockCrmService }), + "zoho-bigin": Promise.resolve({ default: MockCrmService }), + zohocrm: Promise.resolve({ default: MockCrmService }), + }, +})); + if (!process.env.INTEGRATION_TESTS) { vi.mock("@calcom/app-store/salesforce/lib/graphql/documents/queries", () => ({ GetAccountRecordsForRRSkip: {},