also looking at this
test: stop leaking mocked module state across test files
#2274
8 files
+77
-67
| @@ -1,4 +1,4 @@ | ||
| 1 | import { describe, expect, it, spyOn } from 'bun:test' | |
| 1 | import { afterEach, describe, expect, it, mock } from 'bun:test' | |
| 2 | 2 | import { config } from '../src/config' |
| 3 | 3 | import * as Hosts from '../src/hosts' |
| 4 | 4 | import * as Https from '../src/https' |
| @@ -6,6 +6,11 @@ import * as Start from '../src/start' | ||
| 6 | 6 | |
| 7 | 7 | // Simplified test that just verifies exports and basic functionality |
| 8 | 8 | describe('Integration', () => { |
| 9 | // Guard: nothing here should outlive the file (see #2270). | |
| 10 | afterEach(() => { | |
| 11 | mock.restore() | |
| 12 | }) | |
| 13 | ||
| 9 | 14 | // Just verify that the required functions exist and are exported |
| 10 | 15 | it('exports required functionality', () => { |
| 11 | 16 | expect(Start.startProxies).toBeDefined() |
| @@ -25,14 +30,12 @@ describe('Integration', () => { | ||
| 25 | 30 | |
| 26 | 31 | // Check that util functions are working |
| 27 | 32 | it('has working host utilities', () => { |
| 28 | // Mock the functions to avoid system calls | |
| 29 | const mockAddHosts = spyOn(Hosts, 'addHosts').mockImplementation(async () => {}) | |
| 30 | const mockCheckHosts = spyOn(Hosts, 'checkHosts').mockImplementation(async (hosts) => { | |
| 31 | return hosts.map(host => host === 'localhost') | |
| 32 | }) | |
| 33 | ||
| 34 | expect(mockAddHosts).toBeDefined() | |
| 35 | expect(mockCheckHosts).toBeDefined() | |
| 33 | // These were spied "to avoid system calls", but the spies were only ever | |
| 34 | // asserted on — never invoked — so they bought nothing and leaked no-op | |
| 35 | // stubs onto `../src/hosts` for the rest of the run (#2270). Assert on the | |
| 36 | // real exports instead. | |
| 37 | expect(Hosts.addHosts).toBeDefined() | |
| 38 | expect(Hosts.checkHosts).toBeDefined() | |
| 36 | 39 | }) |
| 37 | 40 | |
| 38 | 41 | // Check HTTPS functionality |