Skip to content

Commit

Permalink
jest: Add and use jest-expo preset, again.
Browse files Browse the repository at this point in the history
Done to reduce boring mocks (in particular, remove boring mocks for
things from Expo) in our Jest setup.

A redo of 62621ef and e40c020, reverted in 347aa96, which we
can do following the recent RN upgrade to v0.62 (see 347aa96 for
details).

Since we're on react@16.11.0, use 16.11.0 as the version range for
react-dom, instead of 16.9.0 as we did in 62621ef. (We don't use
any code in react-dom, but we unfortunately have to include it to
satisfy peer dependencies; see 62621ef.)

This time around, we get a peer-dependency warning suggesting we
need to install expo-splash-screen:

"""
warning "jest-expo > @expo/config >
@expo/configure-splash-screen@0.1.17" has unmet peer dependency
"expo-splash-screen@*".
"""

So, do that. It really should go under `devDependencies`, since we
only need it for jest-expo. But I find that react-native-unimodules
is automatically linking `expo-splash-screen`'s native code on iOS
and Android, whether it's in `devDependencies` or `dependencies`.
Although I didn't encounter problems building and running for
release on iOS or Android with it in `devDependencies`, it seems
problematic to link native code from a package we've said is for
development only. So, reluctantly, say that it's not for development
only, by putting it under `dependencies`. We may in fact want to use
it in production one day; if we do, we'll probably need to put
together a Flow libdef.

[1] We can't do the usual thing to prevent it from getting linked,
    adding lines to `react-native.config.js`. It seems Unimodules
    isn't informed by that file, which is where React Native's
    autolinking (a separate process) takes its cues from.

    There may be a way to tell Unimodules to exclude it, but it
    seems to mean calling code in two or three places that's mostly
    meant for internal use; see
    https://forums.expo.io/t/unimodules-what-else-can-i-exclude/41079
    and
    expo/expo#9736 (comment).
  • Loading branch information
chrisbobbe committed Sep 21, 2020
1 parent e122cfb commit c4fca9d
Show file tree
Hide file tree
Showing 6 changed files with 1,946 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public List<Package> getPackageList() {
new expo.modules.filesystem.FileSystemPackage(),
new expo.modules.imageloader.ImageLoaderPackage(),
new expo.modules.permissions.PermissionsPackage(),
new expo.modules.screenorientation.ScreenOrientationPackage()
new expo.modules.screenorientation.ScreenOrientationPackage(),
new expo.modules.splashscreen.SplashScreenPackage()
);
}
}
7 changes: 7 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ PODS:
- EXScreenOrientation (1.0.0):
- React-Core
- UMCore
- EXSplashScreen (0.5.0):
- React
- UMCore
- FBLazyVector (0.62.2)
- FBReactNativeSpec (0.62.2):
- Folly (= 2018.10.22.00)
Expand Down Expand Up @@ -402,6 +405,7 @@ DEPENDENCIES:
- EXImageLoader (from `../node_modules/expo-image-loader/ios`)
- EXPermissions (from `../node_modules/expo-permissions/ios`)
- EXScreenOrientation (from `../node_modules/expo-screen-orientation/ios`)
- EXSplashScreen (from `../node_modules/expo-splash-screen/ios`)
- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
- FBReactNativeSpec (from `../node_modules/react-native/Libraries/FBReactNativeSpec`)
- Flipper (~> 0.33.1)
Expand Down Expand Up @@ -516,6 +520,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/expo-permissions/ios"
EXScreenOrientation:
:path: "../node_modules/expo-screen-orientation/ios"
EXSplashScreen:
:path: "../node_modules/expo-splash-screen/ios"
FBLazyVector:
:path: "../node_modules/react-native/Libraries/FBLazyVector"
FBReactNativeSpec:
Expand Down Expand Up @@ -643,6 +649,7 @@ SPEC CHECKSUMS:
EXImageLoader: 5ad6896fa1ef2ee814b551873cbf7a7baccc694a
EXPermissions: 24b97f734ce9172d245a5be38ad9ccfcb6135964
EXScreenOrientation: 44d3cd3a99a86b9cb681e742697bc2c057d7fbd2
EXSplashScreen: 9423d258b71afa5bf128a83dcb57b636d9900a74
FBLazyVector: 4aab18c93cd9546e4bfed752b4084585eca8b245
FBReactNativeSpec: 5465d51ccfeecb7faa12f9ae0024f2044ce4044e
Flipper: 6c1f484f9a88d30ab3e272800d53688439e50f69
Expand Down
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// These will be used as regexp fragments.
const transformModulesWhitelist = [
'expo-apple-authentication',
'expo-application',
'react-native',
// @rnc/async-storage itself is precompiled, but its mock-helper is not
'@react-native-community/async-storage',
Expand All @@ -24,7 +25,7 @@ const transformModulesWhitelist = [
const transformIgnorePattern = `node_modules/(?!${transformModulesWhitelist.join('|')})`;

module.exports = {
preset: 'react-native',
preset: 'jest-expo',

// Finding and transforming source code.

Expand Down
11 changes: 0 additions & 11 deletions jest/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ jest.mock('react-native-simple-toast', () => ({
showWithGravity: jest.fn(),
}));

jest.mock('expo-application', () => ({
nativeApplicationVersion: '26.23.146',
}));

jest.mock('react-native-device-info', () => ({
getSystemName: jest.fn().mockReturnValue('ios'),
getSystemVersion: jest.fn().mockReturnValue('13.3.1'),
Expand All @@ -105,10 +101,3 @@ jest.mock('react-native-image-picker', () => ({
launchCamera: jest.fn(),
launchImageLibrary: jest.fn(),
}));

jest.mock('expo-apple-authentication', () => ({
AppleAuthenticationButton: jest.fn(),
isAvailableAsync: jest.fn(),
signInAsync: jest.fn(),
// etc. (incomplete)
}));
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"expo-apple-authentication": "^2.1.1",
"expo-application": "^2.1.1",
"expo-screen-orientation": "^1.0.0",
"expo-splash-screen": "^0.5.0",
"immutable": "^4.0.0-rc.12",
"json-stringify-safe": "^5.0.1",
"katex": "^0.11.1",
Expand Down Expand Up @@ -125,6 +126,7 @@
"jest-cli": "^26.4.1",
"jest-environment-jsdom": "^26.3.0",
"jest-environment-jsdom-global": "^2.0.4",
"jest-expo": "^38.0.2",
"jest-extended": "^0.11.5",
"jetifier": "^1.6.5",
"lolex": "^5.1.1",
Expand All @@ -133,7 +135,9 @@
"prettier-eslint": "^11.0.0",
"prettier-eslint-cli": "^5.0.0",
"prop-types": "^15.7.2",
"react-dom": "16.11.0",
"react-native-cli": "^2.0.1",
"react-native-web": "^0.13.3",
"redux-mock-store": "^1.5.1",
"rollup": "^2.26.5",
"typescript": "^3.9.7",
Expand Down
Loading

0 comments on commit c4fca9d

Please sign in to comment.