forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.js
97 lines (87 loc) · 3.45 KB
/
jest.config.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
88
89
90
91
92
93
94
95
96
97
// Modules in `node_modules` which are published in uncompiled form, and
// therefore need to be compiled by Babel before Jest can use them.
//
// These will be used as regexp fragments.
const transformModulesWhitelist = [
'expo-apple-authentication',
'expo-application',
'expo-modules-core',
'expo-sqlite',
'expo-web-browser',
'react-native',
'@react-native',
// @rnc/async-storage itself is precompiled, but its mock-helper is not
'@react-native-async-storage/async-storage',
'@react-native-community/push-notification-ios',
'@expo/react-native-action-sheet',
'react-navigation',
'@sentry/react-native',
'@zulip/',
];
// The rest of `node_modules`, however, should not be transformed. We express this
// with a negative-lookahead suffix, as suggested in the Jest docs:
//
// https://jestjs.io/docs/en/tutorial-react-native#transformignorepatterns-customization
//
// (This value is correctly a string, not a RegExp.)
const transformIgnorePattern = `node_modules/(?!${transformModulesWhitelist.join('|')})`;
const projectForPlatform = platform => {
if (!['ios', 'android'].includes(platform)) {
throw new Error(`Unsupported platform '${platform}'.`);
}
return {
displayName: platform,
// Ideally, these would simply be `jest-expo/ios` and
// `jest-expo/android`; see
// https://github.com/expo/expo/blob/master/packages/jest-expo/README.md#platforms.
// These custom presets are a workaround for a bug:
//
// `jest-expo`'s presets are based on `react-native`'s preset,
// which does something messy: it overwrites the global `Promise`.
// That's facebook/react-native#29303. Jest doesn't work well with
// that; that's facebook/jest#10221.
//
// So, until one of those is fixed, we use these custom presets to
// sandwich the code that replaces `global.Promise` with a fix:
//
// 1) save `global.Promise` to something else on `global`
// 2) let the `react-native` preset do its thing (like mocking RN
// libraries)
// 3) assign `global.Promise` back to what we saved in step 1
preset: platform === 'ios' ? './jest/presetIos' : './jest/presetAndroid',
//
//
// Config for finding and transforming source code.
//
testPathIgnorePatterns: ['/node_modules/', '/src/__tests__/lib/', '-testlib.js$'],
// When some source file foo.js says `import 'bar'`, Jest looks in the
// directories above foo.js for a directory like `node_modules` to find
// `bar` in. If foo.js is behind a `yarn link` symlink and outside our
// tree, that won't work; so have it look at our node_modules too.
moduleDirectories: ['node_modules', '<rootDir>/node_modules'],
transform: {
'^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
},
transformIgnorePatterns: [transformIgnorePattern],
//
//
// Config for the runtime test environment.
//
globals: {
__TEST__: true,
},
timers: 'fake',
globalSetup: './jest/globalSetup.js',
setupFiles: [
'./jest/globalFetch.js',
'./node_modules/react-native-gesture-handler/jestSetup.js',
],
setupFilesAfterEnv: ['./jest/jestSetup.js', 'jest-extended/all'],
};
};
module.exports = {
// The substantive difference between these two is whether `foo.ios.js`
// or `foo.android.js` is used. In particular that also has the effect
// of controlling the value of `Platform.OS`.
projects: [projectForPlatform('ios'), projectForPlatform('android')],
};