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/start-lb-passthrough.test.tsmodified+9-1
Changes to packages/rpx/test/start-lb-passthrough.test.ts
@@ -1,5 +1,5 @@
11import type { MultiProxyConfig } from '../src/types'
2import { describe, expect, it, spyOn } from 'bun:test'
2import { afterEach, describe, expect, it, mock, spyOn } from 'bun:test'
33import * as Start from '../src/start'
44
55/**
@@ -21,6 +21,14 @@ import * as Start from '../src/start'
2121 * single-proxy-in-multi-array tests once this passthrough is corrected).
2222 */
2323describe('startProxies non-shared-listener fallback passes loadBalancer through', () => {
24 // This file already defends against spies leaking IN (see the comment on the
25 // spy below); without this it leaked right back OUT. `Start.startServer` is a
26 // shared export and `spyOn` does not auto-restore, so the no-op stub — and its
27 // call history — reached every later file (#2270).
28 afterEach(() => {
29 mock.restore()
30 })
31
2432 it('a single-entry `proxies` array (no shared listener) forwards loadBalancer to startServer', async () => {
2533 // Matches this file's established convention (see start.test.ts): re-spy
2634 // immediately before the call and inspect the most recent call, since