Skip to content

Commit 7ab2027

Browse files
committed
Add nock.disableNetConnect in vitest setup
1 parent b29751f commit 7ab2027

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/vitest.setup.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
// Vitest setup file
2-
import "./utils/path" // Import to enable String.prototype.toPosix()
1+
import nock from "nock"
32

4-
// Mock fs/promises for tests that need it
5-
import { vi } from "vitest"
3+
import "./utils/path" // Import to enable String.prototype.toPosix().
64

7-
// Global mocks that many tests expect
5+
// Disable network requests by default for all tests.
6+
nock.disableNetConnect()
7+
8+
export function allowNetConnect(host?: string | RegExp) {
9+
if (host) {
10+
nock.enableNetConnect(host)
11+
} else {
12+
nock.enableNetConnect()
13+
}
14+
}
15+
16+
// Global mocks that many tests expect.
817
global.structuredClone = global.structuredClone || ((obj: any) => JSON.parse(JSON.stringify(obj)))

0 commit comments

Comments
 (0)