Преглед изворни кода

Stop unit test runs failing after every test has passed (#581)

An audited action fans out to webhooks and connected integrations without
waiting (logAudit, issueInvoice). In a unit test that lazy import could land
after the test file's environment was torn down; its error was logged into a
closing worker and Vitest exited 1 with "EnvironmentTeardownError: Closing rpc
while onUserConsoleLog was pending". The shared setup now stubs both modules;
tests that care about the fan-out still mock them themselves.
Bernt Christian Egeland пре 21 часа
родитељ
комит
02552ce764
1 измењених фајлова са 15 додато и 0 уклоњено
  1. 15 0
      src/__tests__/setup.ts

+ 15 - 0
src/__tests__/setup.ts

@@ -49,6 +49,21 @@ function interpolate(tpl: string, values?: Record<string, unknown>): string {
   )
 }
 
+// An audited action fans out to webhooks and connected integrations without
+// waiting (logAudit in src/lib/audit.ts, and issueInvoice). In a test that
+// work can outlive the file: on a busy runner the lazy import lands after the
+// environment is torn down, its error is logged into a worker already
+// closing, and the whole run fails with "EnvironmentTeardownError: Closing
+// rpc while onUserConsoleLog was pending" though every test passed. No unit
+// test is about the fan-out by way of an action; one that is mocks these
+// modules itself, which replaces the stubs here.
+vi.mock('@/features/webhooks/Lib/dispatcher', () => ({
+  dispatchWebhookEvent: vi.fn(async () => undefined),
+}))
+vi.mock('@/features/integrations/Lib/events', () => ({
+  notifyIntegrations: vi.fn(async () => undefined),
+}))
+
 // Mock next-intl globally so components using useTranslations can render in tests.
 vi.mock('next-intl', () => ({
   useTranslations: (namespace: string) => {