Skip to content

Commit 8663f7c

Browse files
JPeer264claude
andcommitted
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 <noreply@anthropic.com>
1 parent c20e4f2 commit 8663f7c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎packages/bun/test/integrations/bunserver.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { RequestEventData } from '@sentry/core';
22
import * as SentryCore from '@sentry/core';
3-
import { afterEach, beforeAll, beforeEach, describe, expect, spyOn, test } from 'bun:test';
3+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, spyOn, test } from 'bun:test';
44
import type { BunOptions } from '../../src';
55
import { bunServerIntegration, getDefaultIntegrationsWithoutPerformance, init } from '../../src';
66
import { instrumentBunServe } from '../../src/integrations/bunserver';
@@ -53,6 +53,13 @@ describe('Bun Serve Integration', () => {
5353
port += 1;
5454
});
5555

56+
// The spies replace `@sentry/core` exports for all test files that `bun test` runs after this one
57+
afterAll(() => {
58+
captureExceptionSpy.mockRestore();
59+
continueTraceSpy.mockRestore();
60+
startSpanSpy.mockRestore();
61+
});
62+
5663
test.each(['fetch', 'route'])(
5764
'keeps a streaming %s response span open until the last chunk is consumed',
5865
async mode => {

0 commit comments

Comments
 (0)