ReviewOS

also looking at this

stacks/rpx

test: stop leaking mocked module state across test files

#2274
Merged glennmichael123 wants to merge fix/2270-2271-test-state-leaks into main
8 files +77 -67
packages/rpx/test/integration.test.tsmodified+12-9
Changes to packages/rpx/test/integration.test.ts
@@ -1,4 +1,4 @@
1import { describe, expect, it, spyOn } from 'bun:test'
1import { afterEach, describe, expect, it, mock } from 'bun:test'
22import { config } from '../src/config'
33import * as Hosts from '../src/hosts'
44import * as Https from '../src/https'
@@ -6,6 +6,11 @@ import * as Start from '../src/start'
66
77// Simplified test that just verifies exports and basic functionality
88describe('Integration', () => {
9 // Guard: nothing here should outlive the file (see #2270).
10 afterEach(() => {
11 mock.restore()
12 })
13
914 // Just verify that the required functions exist and are exported
1015 it('exports required functionality', () => {
1116 expect(Start.startProxies).toBeDefined()
@@ -25,14 +30,12 @@ describe('Integration', () => {
2530
2631 // Check that util functions are working
2732 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()
3639 })
3740
3841 // Check HTTPS functionality