Skip to content

Commit 2cdb2a9

Browse files
committed
Fmt
1 parent 77498b1 commit 2cdb2a9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

site/jest.setup.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,33 @@ import "jest-location-mock"
66
import { TextEncoder, TextDecoder } from "util"
77
import { Blob } from "buffer"
88
import jestFetchMock from "jest-fetch-mock"
9+
import { ProxyLatencyReport } from "contexts/useProxyLatency"
10+
import { RegionsResponse } from "api/typesGenerated"
911

1012
jestFetchMock.enableMocks()
1113

14+
// useProxyLatency does some http requests to determine latency.
15+
// This would fail unit testing, or at least make it very slow with
16+
// actual network requests. So just globally mock this hook.
17+
jest.mock("contexts/useProxyLatency", () => ({
18+
useProxyLatency: (proxies?: RegionsResponse) => {
19+
if (!proxies) {
20+
return {} as Record<string, ProxyLatencyReport>
21+
}
22+
23+
return proxies.regions.reduce((acc, proxy) => {
24+
acc[proxy.id] = {
25+
accurate: true,
26+
// Return a constant latency of 8ms.
27+
// If you make this random it could break stories.
28+
latencyMS: 8,
29+
at: new Date(),
30+
}
31+
return acc
32+
}, {} as Record<string, ProxyLatencyReport>)
33+
},
34+
}))
35+
1236
global.TextEncoder = TextEncoder
1337
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Polyfill for jsdom
1438
global.TextDecoder = TextDecoder as any

site/src/testHelpers/renderHelpers.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from "react-router-dom"
2121
import { RequireAuth } from "../components/RequireAuth/RequireAuth"
2222
import { MockUser } from "./entities"
23+
import "./performanceMock"
2324

2425
export const history = createMemoryHistory()
2526

0 commit comments

Comments
 (0)