File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,33 @@ import "jest-location-mock"
6
6
import { TextEncoder , TextDecoder } from "util"
7
7
import { Blob } from "buffer"
8
8
import jestFetchMock from "jest-fetch-mock"
9
+ import { ProxyLatencyReport } from "contexts/useProxyLatency"
10
+ import { RegionsResponse } from "api/typesGenerated"
9
11
10
12
jestFetchMock . enableMocks ( )
11
13
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
+
12
36
global . TextEncoder = TextEncoder
13
37
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Polyfill for jsdom
14
38
global . TextDecoder = TextDecoder as any
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import {
20
20
} from "react-router-dom"
21
21
import { RequireAuth } from "../components/RequireAuth/RequireAuth"
22
22
import { MockUser } from "./entities"
23
+ import "./performanceMock"
23
24
24
25
export const history = createMemoryHistory ( )
25
26
You can’t perform that action at this time.
0 commit comments