|
10 | 10 |
|
11 | 11 | import { beforeEach, describe, expect, mock, test } from "bun:test"; |
12 | 12 |
|
| 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 | + |
13 | 20 | // ============================================================================ |
14 | 21 | // Mock Setup - All dependency modules mocked before importing resolve-target |
15 | 22 | // ============================================================================ |
@@ -53,15 +60,17 @@ mock.module("../../src/lib/db/defaults.js", () => ({ |
53 | 60 | getDefaultProject: mockGetDefaultProject, |
54 | 61 | })); |
55 | 62 |
|
| 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. |
56 | 68 | mock.module("../../src/lib/dsn/index.js", () => ({ |
57 | 69 | detectDsn: mockDetectDsn, |
58 | 70 | detectAllDsns: mockDetectAllDsns, |
59 | 71 | findProjectRoot: mockFindProjectRoot, |
60 | 72 | 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, |
65 | 74 | })); |
66 | 75 |
|
67 | 76 | mock.module("../../src/lib/db/project-cache.js", () => ({ |
|
0 commit comments