also looking at this
test: stop leaking mocked module state across test files
#2274
8 files
+77
-67
| @@ -1,4 +1,4 @@ | ||
| 1 | import { beforeEach, describe, expect, it, spyOn } from 'bun:test' | |
| 1 | import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test' | |
| 2 | 2 | import * as hostsModule from '../src/hosts' |
| 3 | 3 | import { dropStaleRpxHostsLines, filterRpxHostsEntries, hostsLineMapsHost, isLoopbackDevelopmentHost, parseHostsLine } from '../src/hosts' |
| 4 | 4 | |
| @@ -34,6 +34,14 @@ describe('hosts', () => { | ||
| 34 | 34 | }) |
| 35 | 35 | }) |
| 36 | 36 | |
| 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 | ||
| 37 | 45 | describe('hosts file operations', () => { |
| 38 | 46 | it('checks hosts entries correctly', async () => { |
| 39 | 47 | const result = await hostsModule.checkHosts(['localhost', 'example.com'], true) |