From f682bd371c106540d4f1a46faf272ba360d3d790 Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Sat, 10 Oct 2026 08:38:47 +0200 Subject: [PATCH] test(bun): Restore @sentry/core spies after the Bun.serve tests bunserver.test.ts replaces startSpanManual, continueTrace and captureException of @sentry/core and never restores them. In Bun the spies stay for every later test file in the same process, so when bunHttpServer.test.ts runs next, its handler gets no active span. The test file order of bun test follows the directory listing. On GitHub runners bunRuntimeMetrics.test.ts ran in between and its jest.restoreAllMocks() removed the spies; on Namespace runners it does not. Co-Authored-By: Claude Opus 5.5 --- packages/bun/test/integrations/bunserver.test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/bun/test/integrations/bunserver.test.ts b/packages/bun/test/integrations/bunserver.test.ts index 0a25b655a892..bec2b892ea3a 100644 --- a/packages/bun/test/integrations/bunserver.test.ts +++ b/packages/bun/test/integrations/bunserver.test.ts @@ -1,6 +1,6 @@ import type { RequestEventData } from '@sentry/core'; import * as SentryCore from '@sentry/core'; -import { afterEach, beforeAll, beforeEach, describe, expect, spyOn, test } from 'bun:test'; +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, spyOn, test } from 'bun:test'; import type { BunOptions } from '../../src'; import { bunServerIntegration, getDefaultIntegrationsWithoutPerformance, init } from '../../src'; import { instrumentBunServe } from '../../src/integrations/bunserver'; @@ -53,6 +53,13 @@ describe('Bun Serve Integration', () => { port += 1; }); + // The spies replace `@sentry/core` exports for all test files that `bun test` runs after this one + afterAll(() => { + captureExceptionSpy.mockRestore(); + continueTraceSpy.mockRestore(); + startSpanSpy.mockRestore(); + }); + test.each(['fetch', 'route'])( 'keeps a streaming %s response span open until the last chunk is consumed', async mode => {