-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSetup.ts
More file actions
51 lines (45 loc) · 1.75 KB
/
Copy pathtestSetup.ts
File metadata and controls
51 lines (45 loc) · 1.75 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
/**
* Bun test preload — runs before any test file is loaded.
* Mocks native modules that can't be evaluated in a Node.js test environment:
* - react-native: uses Flow `import typeof` syntax bun cannot parse
* - react-native-reanimated: imports React Native native/runtime APIs during module init
* - expo-modules-core: calls requireNativeModule() which needs the Android runtime
* - vescape-core: our custom Expo module, also needs Android runtime
*/
import { mock } from 'bun:test'
/**
* Baseline `react-native` surface. A test needing more (AppState, …) must spread this rather
* than replace it — `mock.module` is global, so a bare override strips these for every file
* loaded after it.
*/
export const reactNativeStub = {
// Tests run without a scheduler, so deferred work resolves immediately.
InteractionManager: {
runAfterInteractions: (task: () => void) => {
task()
return { cancel: () => {} }
},
},
// Stores that re-pull on foreground subscribe at module scope; nothing changes state in tests.
AppState: {
currentState: 'active',
addEventListener: (_event: string, _cb: unknown) => ({ remove: () => {} }),
},
}
mock.module('react-native', () => ({ ...reactNativeStub }))
mock.module('react-native-reanimated', () => ({
makeMutable: <T>(value: T) => ({ value }),
}))
mock.module('react-native-worklets', () => ({
// No UI runtime in tests — run the worklet synchronously on the JS thread.
scheduleOnUI: <Args extends unknown[]>(fn: (...args: Args) => unknown, ...args: Args) =>
fn(...args),
}))
mock.module('expo-modules-core', () => ({
requireNativeModule: (_name: string) => ({}),
EventEmitter: class {
addListener(_event: string, _cb: unknown) {
return { remove: () => {} }
}
},
}))