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/hosts.test.tsmodified+9-1
Changes to packages/rpx/test/hosts.test.ts
@@ -1,4 +1,4 @@
1import { beforeEach, describe, expect, it, spyOn } from 'bun:test'
1import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test'
22import * as hostsModule from '../src/hosts'
33import { dropStaleRpxHostsLines, filterRpxHostsEntries, hostsLineMapsHost, isLoopbackDevelopmentHost, parseHostsLine } from '../src/hosts'
44
@@ -34,6 +34,14 @@ describe('hosts', () => {
3434 })
3535 })
3636
37 // `bun test` shares one module registry across every file in the process and
38 // `spyOn` does not auto-restore, so without this these three stubs stay
39 // installed on `../src/hosts` for every file that runs after this one —
40 // silently turning real hosts-file writes into no-ops there (#2270).
41 afterEach(() => {
42 mock.restore()
43 })
44
3745 describe('hosts file operations', () => {
3846 it('checks hosts entries correctly', async () => {
3947 const result = await hostsModule.checkHosts(['localhost', 'example.com'], true)