Skip to content

Commit 138b073

Browse files
committed
fix(test): pass through real formatMultipleProjectsFooter in mock
Bun's mock.module() leaks across test files in the same run. The simplified stub for formatMultipleProjectsFooter in the dsn/index.js mock was poisoning errors.test.ts, causing 4 failures in test:isolated. Import the real function from its source file (dsn/errors.js) and pass it through the mock so the leaked version retains real behavior. Fixes #258
1 parent 618671d commit 138b073

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

test/isolated/resolve-target.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
import { beforeEach, describe, expect, mock, test } from "bun:test";
1212

13+
// IMPORTANT: Import the real formatMultipleProjectsFooter from its source file
14+
// (not the barrel dsn/index.js). We pass this through the mock below so that
15+
// if Bun leaks the mock.module() into other test files (which it does — see
16+
// https://github.com/getsentry/cli/issues/258), the leaked version still has
17+
// the real behavior instead of a simplified stub.
18+
import { formatMultipleProjectsFooter } from "../../src/lib/dsn/errors.js";
19+
1320
// ============================================================================
1421
// Mock Setup - All dependency modules mocked before importing resolve-target
1522
// ============================================================================
@@ -53,15 +60,17 @@ mock.module("../../src/lib/db/defaults.js", () => ({
5360
getDefaultProject: mockGetDefaultProject,
5461
}));
5562

63+
// Bun's mock.module() replaces the ENTIRE barrel module. Since resolve-target.ts
64+
// imports formatMultipleProjectsFooter from dsn/index.js, we must include it here.
65+
// We pass through the real function (imported above from dsn/errors.js) rather than
66+
// a stub, because Bun leaks mock.module() state across test files in the same run
67+
// and a simplified stub would break tests in dsn/errors.test.ts.
5668
mock.module("../../src/lib/dsn/index.js", () => ({
5769
detectDsn: mockDetectDsn,
5870
detectAllDsns: mockDetectAllDsns,
5971
findProjectRoot: mockFindProjectRoot,
6072
getDsnSourceDescription: mockGetDsnSourceDescription,
61-
formatMultipleProjectsFooter: (projects: unknown[]) =>
62-
(projects as { orgDisplay: string; projectDisplay: string }[]).length > 1
63-
? `Found ${(projects as unknown[]).length} projects`
64-
: "",
73+
formatMultipleProjectsFooter,
6574
}));
6675

6776
mock.module("../../src/lib/db/project-cache.js", () => ({

0 commit comments

Comments
 (0)