forked from PelagusWallet/pelagus-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupJest.ts
46 lines (40 loc) · 1.47 KB
/
setupJest.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as util from "util"
import Dexie from "dexie"
import logger, { LogLevel } from "@tallyho/tally-background/lib/logger"
const IS_CI = process.env.CI === "true"
// When running tests, Jest will point to each expectation that failed for failed tests in the
// console output. For this reason, we want to minimize the amount of messages logged during
// CI workflows to get an overview of both failed expectations and possible errors.
// This is not the case during development, hence, we set the minimum log level to warning
// as it helps with debugging while writing new tests.
logger.logLevel = IS_CI ? LogLevel.error : LogLevel.warn
// ref: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
// ref: https://github.com/jsdom/jsdom/issues/2524
Object.defineProperty(window, "TextEncoder", {
writable: true,
value: util.TextEncoder,
})
Object.defineProperty(window, "TextDecoder", {
writable: true,
value: util.TextDecoder,
})
Object.defineProperty(window.navigator, "usb", {
writable: true,
value: {
getDevices: () => [],
addEventListener: () => {},
},
})
// Prevent Dexie from caching indexedDB global so fake-indexeddb
// can reset properly.
Object.defineProperty(Dexie.dependencies, "indexedDB", {
get: () => indexedDB,
})
// Stub fetch calls
Object.defineProperty(window, "fetch", {
writable: true,
value: (url: string) => {
// eslint-disable-next-line no-console
console.warn("Uncaught fetch call to: \n", url)
},
})