also looking at this
test: stop leaking mocked module state across test files
#2274
8 files
+77
-67
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | * a single entry fell through to `startServer`, which never receives |
| 11 | 11 | * `productionTlsConfig` at all and unconditionally mints/uses a dev cert. |
| 12 | 12 | */ |
| 13 | import { afterEach, describe, expect, it, spyOn } from 'bun:test' | |
| 13 | import { afterEach, describe, expect, it, mock, spyOn } from 'bun:test' | |
| 14 | 14 | import * as fsp from 'node:fs/promises' |
| 15 | 15 | import * as os from 'node:os' |
| 16 | 16 | import * as path from 'node:path' |
| @@ -20,6 +20,11 @@ describe('startProxies single-proxy production certs', () => { | ||
| 20 | 20 | let dir: string | undefined |
| 21 | 21 | |
| 22 | 22 | 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() | |
| 23 | 28 | if (dir) |
| 24 | 29 | await fsp.rm(dir, { recursive: true, force: true }).catch(() => {}) |
| 25 | 30 | dir = undefined |
| @@ -61,8 +66,5 @@ describe('startProxies single-proxy production certs', () => { | ||
| 61 | 66 | // The individual (dev-cert-only) path must NOT have been used — that's |
| 62 | 67 | // exactly the path that was silently dropping the real production cert. |
| 63 | 68 | expect(startServerSpy).not.toHaveBeenCalled() |
| 64 | ||
| 65 | createSharedSpy.mockRestore() | |
| 66 | startServerSpy.mockRestore() | |
| 67 | 69 | }) |
| 68 | 70 | }) |