Skip to content

test(bun): Restore @sentry/core spies after the Bun.serve tests - #25276

Merged
JPeer264 merged 1 commit into
developfrom
jp/flaky-bun-serve-spies
Oct 14, 2026
Merged

JPeer264 merged 1 commit into
developfrom
jp/flaky-bun-serve-spies

Conversation

@JPeer264

Copy link
Copy Markdown
Member

This restores the @sentry/core spies that bunserver.test.ts creates (startSpanManual, continueTrace and captureException) in an afterAll.

Why

bun test runs all test files in one process, in the order in which the filesystem lists them. The spies stayed active for the next files, so when bunHttpServer.test.ts ran next, its request handler had no active span and two tests failed. On GitHub runners bunRuntimeMetrics.test.ts ran in between, and its jest.restoreAllMocks() hid the bug. Other runners list the files in a different order.

In that file order on Linux with Bun 1.3.14, 2 of 81 tests failed before this change, and all 81 pass after it.

Failed on CI: https://github.com/getsentry/sentry-javascript/actions/runs/38031083791/job/114152141693

@JPeer264
JPeer264 added this pull request to stack #25283 October 12, 2026 12:19
@JPeer264
JPeer264 marked this pull request as ready for review October 12, 2026 12:21
@JPeer264
JPeer264 requested a review from a team as a code owner October 12, 2026 12:21
@JPeer264
JPeer264 requested review from isaacs and mydea and removed request for a team October 12, 2026 12:21
@JPeer264 JPeer264 self-assigned this Oct 12, 2026
@JPeer264
JPeer264 requested a review from andreiborza October 12, 2026 12:21
@JPeer264
JPeer264 removed this pull request from stack #25283 October 13, 2026 15:29
@JPeer264
JPeer264 added this pull request to stack #25335 October 13, 2026 15:29
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>
@JPeer264
JPeer264 force-pushed the jp/flaky-bun-serve-spies branch from 83d7d75 to f682bd3 Compare October 13, 2026 15:36
@JPeer264
JPeer264 merged commit 8c65689 into develop Oct 14, 2026
167 of 171 checks passed
@JPeer264
JPeer264 deleted the jp/flaky-bun-serve-spies branch October 14, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants