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-single-proxy-production-certs.test.tsmodified+6-4
Changes to packages/rpx/test/start-single-proxy-production-certs.test.ts
@@ -10,7 +10,7 @@
1010 * a single entry fell through to `startServer`, which never receives
1111 * `productionTlsConfig` at all and unconditionally mints/uses a dev cert.
1212 */
13import { afterEach, describe, expect, it, spyOn } from 'bun:test'
13import { afterEach, describe, expect, it, mock, spyOn } from 'bun:test'
1414import * as fsp from 'node:fs/promises'
1515import * as os from 'node:os'
1616import * as path from 'node:path'
@@ -20,6 +20,11 @@ describe('startProxies single-proxy production certs', () => {
2020 let dir: string | undefined
2121
2222 afterEach(async () => {
23 // Restore on EVERY path: the mockRestore()s used to sit at the very end of
24 // the `it`, so any assertion above them left `startServer` a permanent no-op
25 // and `createSharedProxyServer` permanently returning null for the rest of
26 // the run (#2270).
27 mock.restore()
2328 if (dir)
2429 await fsp.rm(dir, { recursive: true, force: true }).catch(() => {})
2530 dir = undefined
@@ -61,8 +66,5 @@ describe('startProxies single-proxy production certs', () => {
6166 // The individual (dev-cert-only) path must NOT have been used — that's
6267 // exactly the path that was silently dropping the real production cert.
6368 expect(startServerSpy).not.toHaveBeenCalled()
64
65 createSharedSpy.mockRestore()
66 startServerSpy.mockRestore()
6769 })
6870})