This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 190
/
jest.setup.js
87 lines (76 loc) · 1.78 KB
/
jest.setup.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import MockDate from "mockdate";
import { env } from "utils/testing-library";
import { bootEnvWithProfileFixtures } from "utils/test-helpers";
jest.mock("@ledgerhq/hw-transport-node-hid-singleton", () => {
const { createTransportReplayer } = require("@ledgerhq/hw-transport-mocker");
return createTransportReplayer();
});
jest.mock("electron", () => {
const setContentProtection = jest.fn();
return {
ipcMain: {
handle: jest.fn(),
invoke: jest.fn(),
on: jest.fn(),
removeListener: jest.fn(),
send: jest.fn(),
},
ipcRenderer: {
handle: jest.fn(),
invoke: jest.fn(),
on: jest.fn(),
removeListener: jest.fn(),
send: jest.fn(),
},
remote: {
app: {
isPackaged: true,
},
dialog: {
showOpenDialog: jest.fn(),
showSaveDialog: jest.fn(),
},
getCurrentWindow: () => ({ setContentProtection }),
nativeTheme: {
shouldUseDarkColors: true,
themeSource: "system",
},
powerMonitor: {
getSystemIdleTime: jest.fn(),
},
},
shell: {
openExternal: jest.fn(),
},
};
});
jest.mock("fs", () => {
const fs = jest.requireActual(`fs`);
return {
...fs,
readFileSync: (filepath, encoding) => {
// Exceptions
if (filepath === "path/to/sample-export.json") return "";
// Use actual
return fs.readFileSync(filepath, encoding);
},
writeFileSync: jest.fn(),
};
});
beforeAll(async () => {
await bootEnvWithProfileFixtures({ env, shouldRestoreDefaultProfile: true });
// Mark profiles as restored, to prevent multiple restoration in profile synchronizer
process.env.TEST_PROFILES_RESTORE_STATUS = "restored";
});
beforeEach(() => {
MockDate.set(new Date("2020-07-01T00:00:00.000Z"));
});
afterEach(() => {
MockDate.reset();
});
afterAll(() => {
if (global.gc) {
global.gc();
}
});
window.scrollTo = jest.fn();