Skip to content

Commit db3166f

Browse files
MSW: passthrough gravatar in dev
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
1 parent e188515 commit db3166f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mocks/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ const miscHandlers = [
5454
},
5555
),
5656
http.head('https://www.gravatar.com/avatar/:md5Hash', async () => {
57-
// In mocks mode we want deterministic behavior and to avoid external HTTP
58-
// requests that can flake in CI (even when DNS works).
57+
// In development, allow real Gravatar lookups when possible.
58+
// In tests/CI (and other non-dev modes), return 404 deterministically to
59+
// avoid flaky external HTTP requests.
60+
if (process.env.NODE_ENV !== 'development') {
61+
return HttpResponse.json(null, { status: 404 })
62+
}
63+
if (await isConnectedToTheInternet()) return passthrough()
5964
return HttpResponse.json(null, { status: 404 })
6065
}),
6166
http.get(/http:\/\/(localhost|127\.0\.0\.1):\d+\/.*/, async () =>

0 commit comments

Comments
 (0)