-
Notifications
You must be signed in to change notification settings - Fork 519
Expand file tree
/
Copy pathjest-setup.js
More file actions
131 lines (108 loc) · 3.15 KB
/
Copy pathjest-setup.js
File metadata and controls
131 lines (108 loc) · 3.15 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* eslint-disable no-undef */
// require('react-native-reanimated').setUpTests();
// Reset process.exitCode between tests. The monorepo-wide unittest runs CLI
// command tests (apps/cli/src/__tests__/*.test.ts) that set process.exitCode
// while asserting non-zero exit codes; without this hook the last such value
// leaks into Node's final exit code and breaks the CI unittest job even when
// every test passes.
afterEach(() => {
process.exitCode = 0;
});
// FIX: ReferenceError: self is not defined
globalThis.self = globalThis.self || globalThis;
class LocalStorageMock {
constructor() {
this.store = {};
}
clear() {
this.store = {};
}
getItem(key) {
return this.store[key] || null;
}
setItem(key, value) {
this.store[key] = String(value);
}
removeItem(key) {
delete this.store[key];
}
}
globalThis.localStorage = new LocalStorageMock();
globalThis.$$onekeyAppStorage = new LocalStorageMock();
globalThis.addEventListener = jest.fn;
globalThis.fetch = require('node-fetch');
globalThis.WebSocket = require('isomorphic-ws');
const MockMMKV = require('./apps/desktop/app/libs/react-native-mmkv-mock');
if (typeof structuredClone === 'undefined') {
globalThis.structuredClone = require('@ungap/structured-clone').default;
}
jest.mock('react-native-zip-archive', () => ({
zip: jest.fn(),
}));
jest.mock('@onekeyfe/react-native-native-logger', () => ({
NativeLogger: {
write: jest.fn(),
getLogDirectory: jest.fn(() => ''),
getLogFilePaths: jest.fn(() => Promise.resolve([])),
deleteLogFiles: jest.fn(() => Promise.resolve()),
},
}));
jest.mock('@sentry/electron/renderer', () => ({
init: () => jest.fn(),
}));
jest.mock('@sentry/react', () => ({
init: () => jest.fn(),
}));
jest.mock('@sentry/react-native', () => ({
init: () => jest.fn(),
reactNavigationIntegration: () => jest.fn(),
reactNativeTracingIntegration: () => jest.fn(),
TimeToInitialDisplay: () => jest.fn(),
TimeToFullDisplay: () => jest.fn(),
}));
jest.mock('expo-localization', () => ({
locale: '',
}));
jest.mock('expo-device', () => ({
deviceType: null,
DeviceType: {
UNKNOWN: 0,
PHONE: 1,
TABLET: 2,
DESKTOP: 3,
TV: 4,
},
brand: null,
manufacturer: null,
modelName: null,
designName: null,
productName: null,
deviceYearClass: null,
totalMemory: null,
supportedCpuArchitectures: null,
osName: null,
osVersion: null,
osBuildId: null,
osInternalBuildId: null,
osBuildFingerprint: null,
platformApiLevel: null,
deviceName: null,
modelId: null,
isDevice: false,
}));
jest.mock('react-native-mmkv', () => ({
__esModule: true,
createMMKV: MockMMKV.createMMKV,
}));
// ** shim TextEncoder
// const { TextEncoder, TextDecoder } = require('util');
// global.TextEncoder = TextEncoder;
// global.TextDecoder = TextDecoder;
// ** shim App variables
// require('./apps/shim');
// ** Array, Buffer, Error
// https://github.com/facebook/jest/issues/2549
// ** asm.js support
// Linking failure in asm.js: Unexpected stdlib member
// ** await import() support
// Error: You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/ecmascript-modules