Skip to content

Commit 6f0524a

Browse files
committed
test: make custom manual tests easy to add to e2e app
1 parent 8592e65 commit 6f0524a

File tree

7 files changed

+274
-4
lines changed

7 files changed

+274
-4
lines changed

tests/app.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
*/
1818

1919
import React from 'react';
20-
import { StyleSheet, View, StatusBar, AppRegistry } from 'react-native';
20+
import { StyleSheet, View, StatusBar, AppRegistry, Text } from 'react-native';
2121

2222
import { JetProvider, ConnectionText, StatusEmoji, StatusText } from 'jet';
2323

24+
import { LocalTests } from './local-test-component';
25+
2426
const platformSupportedModules = [];
2527

2628
if (Platform.other) {
@@ -266,6 +268,11 @@ function App() {
266268
<>
267269
<StatusBar hidden />
268270
<View style={styles.container}>
271+
<View style={styles.hardRule} />
272+
<Text>Local Manual Tests:</Text>
273+
<LocalTests />
274+
<View style={styles.hardRule} />
275+
<Text>Automated Tests:</Text>
269276
<JetProvider tests={loadTests}>
270277
<ConnectionText style={styles.connectionText} />
271278
<View style={styles.statusContainer}>
@@ -308,6 +315,11 @@ const styles = StyleSheet.create({
308315
textAlign: 'center',
309316
color: 'black',
310317
},
318+
hardRule: {
319+
height: 1,
320+
backgroundColor: 'black',
321+
width: '100%',
322+
},
311323
});
312324

313325
AppRegistry.registerComponent('testing', () => App);

tests/local-test-component.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* eslint-disable react/react-in-jsx-scope */
2+
3+
// Add new components in `local-tests` sub-directory,
4+
// with a corresponding import/export in the `local-tests/index.js` file
5+
//
6+
// that file itself is copied during `yarn lerna:prepare` from
7+
// `local-tests/index.example.js` if it does not exist, then
8+
// you are free to modify it
9+
//
10+
// Why do we maintain a list and copy a template?
11+
//
12+
// 1) react-native has no way to do dynamic requires or imports, they require
13+
// constant strings, so we can't just read directory contents and dynamically
14+
// iterate on them unfortunately. So we have to maintain a list of local-only things.
15+
//
16+
// 2) But if you maintain a local-only change, you risk of accidentally committing
17+
// the local-only changes. To keep local changes without commit risk we have to
18+
// do a template copy from an example.
19+
20+
import { TestComponents } from './local-tests';
21+
22+
export function LocalTests() {
23+
return <TestComponents />;
24+
}

tests/local-tests/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# To start with, we want nothing in this directory in general
2+
*
3+
4+
# ... except our template index file (copied during prepare)
5+
!index.example.js
6+
# ... our example component
7+
!crash-test.jsx
8+
# ... and this gitignore file
9+
!.gitignore

tests/local-tests/crash-test.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable react/react-in-jsx-scope */
2+
import { Button, StyleSheet, Text, View } from 'react-native';
3+
import { crash, getCrashlytics } from '@react-native-firebase/crashlytics';
4+
5+
export function CrashTestComponent() {
6+
return (
7+
<View style={styles.horizontalCentered}>
8+
<Text>Crashlytics:</Text>
9+
<Button
10+
style={{ color: 'blue', flex: 1 }}
11+
title="JS Crash"
12+
onPress={() => nonExistentObject.nonExistentFunction()}
13+
/>
14+
<Button
15+
style={{ color: 'blue', flex: 1 }}
16+
title="Native Crash"
17+
onPress={() => crash(getCrashlytics())}
18+
/>
19+
</View>
20+
);
21+
}
22+
23+
const styles = StyleSheet.create({
24+
horizontalCentered: {
25+
flexDirection: 'row',
26+
justifyContent: 'space-between',
27+
alignItems: 'center',
28+
alignContent: 'center',
29+
paddingHorizontal: 10,
30+
},
31+
});

tests/local-tests/index.example.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint-disable react/react-in-jsx-scope */
2+
import { View } from 'react-native';
3+
4+
import { CrashTestComponent } from './crash-test.jsx';
5+
6+
// import your components from your local-tests jsx file here...
7+
8+
const testComponents = [
9+
CrashTestComponent,
10+
11+
// List your imported components here...
12+
];
13+
14+
export function TestComponents() {
15+
return testComponents.map((component, index) => {
16+
return <View key={index}>{component.call()}</View>;
17+
});
18+
}

tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build:clean": "rimraf dist && rimraf android/build && rimraf android/app/build && rimraf android/.gradle && rimraf ios/build && rimraf macos/build",
77
"build:macos": "xcodebuild CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ -workspace macos/io.invertase.testing.xcworkspace -scheme io.invertase.testing-macOS -configuration Debug -derivedDataPath macos/build | xcbeautify",
8-
"prepare": "patch-package"
8+
"prepare": "patch-package && cd local-tests && (yarn cpy --no-overwrite index.example.js ./ --rename=index.js || echo 'Looks like the local test file is already there. Previous copy error may be ignored.')"
99
},
1010
"dependencies": {
1111
"@react-native-async-storage/async-storage": "^2.1.1",
@@ -43,6 +43,7 @@
4343
"@react-native/metro-config": "^0.77.1",
4444
"assert": "^2.1.0",
4545
"axios": "^1.7.9",
46+
"cpy-cli": "^5.0.0",
4647
"detox": "20.34.0",
4748
"firebase": "^11.3.1",
4849
"firebase-tools": "^13.31.1",

0 commit comments

Comments
 (0)