Skip to content

Commit 4c0ac86

Browse files
committed
test: added tests for RN61 and Expo35
1 parent 1e70264 commit 4c0ac86

File tree

87 files changed

+17531
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+17531
-0
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,10 @@
2424
"open": "^7.0.0",
2525
"rimraf": "^3.0.0",
2626
"source-map-explorer": "^2.1.2"
27+
},
28+
"scripts": {
29+
"test": "yarn test:rn61 && yarn test:expo35",
30+
"test:rn61": "cd test/RN61 && npx ../.. && cd ../..",
31+
"test:expo35": "cd test/Expo35 && npx ../.. && cd ../.."
2732
}
2833
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"0cae4d70c6df3e5e96ee8b5c442b59d55c8ab8deb466992ab9abc523822f2a1b": true,
3+
"e997a5256149a4b76e6bfd6cbf519c5e5a0f1d278a3d8fa1253022b03c90473b": true,
4+
"af683c96e0ffd2cf81287651c9433fa44debc1220ca7cb431fe482747f34a505": true,
5+
"e7fc0741cc6562975a990e3d9ef820571588dab20aba97032df9f00caa9cd57a": true
6+
}

test/Expo35/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules/**/*
2+
.expo/*
3+
npm-debug.*
4+
*.jks
5+
*.p8
6+
*.p12
7+
*.key
8+
*.mobileprovision
9+
*.orig.*
10+
web-build/
11+
web-report/
12+
13+
# macOS
14+
.DS_Store

test/Expo35/App.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { AppLoading } from 'expo';
2+
import { Asset } from 'expo-asset';
3+
import * as Font from 'expo-font';
4+
import React, { useState } from 'react';
5+
import { Platform, StatusBar, StyleSheet, View } from 'react-native';
6+
import { Ionicons } from '@expo/vector-icons';
7+
8+
import AppNavigator from './navigation/AppNavigator';
9+
10+
export default function App(props) {
11+
const [isLoadingComplete, setLoadingComplete] = useState(false);
12+
13+
if (!isLoadingComplete && !props.skipLoadingScreen) {
14+
return (
15+
<AppLoading
16+
startAsync={loadResourcesAsync}
17+
onError={handleLoadingError}
18+
onFinish={() => handleFinishLoading(setLoadingComplete)}
19+
/>
20+
);
21+
} else {
22+
return (
23+
<View style={styles.container}>
24+
{Platform.OS === 'ios' && <StatusBar barStyle="default" />}
25+
<AppNavigator />
26+
</View>
27+
);
28+
}
29+
}
30+
31+
async function loadResourcesAsync() {
32+
await Promise.all([
33+
Asset.loadAsync([
34+
require('./assets/images/robot-dev.png'),
35+
require('./assets/images/robot-prod.png'),
36+
]),
37+
Font.loadAsync({
38+
// This is the font that we are using for our tab bar
39+
...Ionicons.font,
40+
// We include SpaceMono because we use it in HomeScreen.js. Feel free to
41+
// remove this if you are not using it in your app
42+
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
43+
}),
44+
]);
45+
}
46+
47+
function handleLoadingError(error) {
48+
// In this case, you might want to report the error to your error reporting
49+
// service, for example Sentry
50+
console.warn(error);
51+
}
52+
53+
function handleFinishLoading(setLoadingComplete) {
54+
setLoadingComplete(true);
55+
}
56+
57+
const styles = StyleSheet.create({
58+
container: {
59+
flex: 1,
60+
backgroundColor: '#fff',
61+
},
62+
});

test/Expo35/__tests__/App-test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import NavigationTestUtils from 'react-navigation/NavigationTestUtils';
3+
import renderer from 'react-test-renderer';
4+
5+
import App from '../App';
6+
7+
jest.mock('expo', () => ({
8+
AppLoading: 'AppLoading',
9+
}));
10+
11+
jest.mock('../navigation/AppNavigator', () => 'AppNavigator');
12+
13+
describe('App', () => {
14+
jest.useFakeTimers();
15+
16+
beforeEach(() => {
17+
NavigationTestUtils.resetInternalState();
18+
});
19+
20+
it(`renders the loading screen`, () => {
21+
const tree = renderer.create(<App />).toJSON();
22+
expect(tree).toMatchSnapshot();
23+
});
24+
25+
it(`renders the root without loading screen`, () => {
26+
const tree = renderer.create(<App skipLoadingScreen />).toJSON();
27+
expect(tree).toMatchSnapshot();
28+
});
29+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`App renders the loading screen 1`] = `
4+
<AppLoading
5+
onError={[Function]}
6+
onFinish={[Function]}
7+
startAsync={[Function]}
8+
/>
9+
`;
10+
11+
exports[`App renders the root without loading screen 1`] = `
12+
<View
13+
style={
14+
Object {
15+
"backgroundColor": "#fff",
16+
"flex": 1,
17+
}
18+
}
19+
>
20+
<AppNavigator />
21+
</View>
22+
`;

test/Expo35/app.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"expo": {
3+
"name": "Bundle Visualizer",
4+
"slug": "Expo35",
5+
"privacy": "public",
6+
"sdkVersion": "36.0.0",
7+
"platforms": [
8+
"ios",
9+
"android",
10+
"web"
11+
],
12+
"version": "1.0.0",
13+
"orientation": "portrait",
14+
"icon": "./assets/images/icon.png",
15+
"splash": {
16+
"image": "./assets/images/splash.png",
17+
"resizeMode": "contain",
18+
"backgroundColor": "#ffffff"
19+
},
20+
"updates": {
21+
"fallbackToCacheTimeout": 0
22+
},
23+
"assetBundlePatterns": [
24+
"**/*"
25+
],
26+
"ios": {
27+
"supportsTablet": true
28+
}
29+
}
30+
}
91.1 KB
Binary file not shown.

test/Expo35/assets/images/icon.png

699 Bytes
Loading
4.93 KB
Loading

0 commit comments

Comments
 (0)