Skip to content

Commit f8d5a9d

Browse files
committed
test: unify the manual and automated tests
there shouldn't be a need to have a separate app, and if we have manual tests they should be generally available vs require manual fiddling to run
1 parent 65b4f41 commit f8d5a9d

File tree

15 files changed

+157
-241
lines changed

15 files changed

+157
-241
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
"tests:jest-watch": "jest --watch",
2525
"tests:jest-coverage": "jest --coverage",
2626
"tests:packager:chrome": "cd tests && yarn react-native start --reset-cache",
27-
"tests:packager:jet": "cd tests && cross-env REACT_DEBUGGER=\"echo nope\" yarn react-native start --client-logs",
28-
"tests:packager:jet-ci": "cd tests && (mkdir $HOME/.metro || true) && cross-env TMPDIR=$HOME/.metro REACT_DEBUGGER=\"echo nope\" yarn react-native start",
29-
"tests:packager:jet-reset-cache": "cd tests && cross-env REACT_DEBUGGER=\"echo nope\" yarn react-native start --reset-cache",
27+
"tests:packager:jet": "cd tests && yarn react-native start --client-logs",
28+
"tests:packager:jet-ci": "cd tests && (mkdir $HOME/.metro || true) && cross-env TMPDIR=$HOME/.metro yarn react-native start",
29+
"tests:packager:jet-reset-cache": "cd tests && yarn react-native start --reset-cache",
3030
"tests:emulator:prepare": "cd .github/workflows/scripts/functions && yarn && yarn build",
3131
"tests:emulator:start": "run-script-os",
3232
"tests:emulator:start:default": "yarn tests:emulator:prepare && cd ./.github/workflows/scripts && ./start-firebase-emulator.sh --no-daemon",
@@ -36,6 +36,7 @@
3636
"tests:android:build:default": "cd tests && yarn detox build --configuration android.emu.debug",
3737
"tests:android:build:windows": "cd tests && yarn detox build --configuration android.emu.debug.windows",
3838
"tests:android:build:release": "cd tests && yarn detox build --configuration android.emu.release",
39+
"tests:android:manual": "cd tests && yarn react-native run-android",
3940
"tests:android:test": "cd tests && yarn detox test --configuration android.emu.debug",
4041
"tests:android:test:debug": "cd tests && yarn detox test --configuration android.emu.debug --inspect",
4142
"tests:android:test-reuse": "cd tests && yarn detox test --configuration android.emu.debug --reuse",
@@ -44,6 +45,7 @@
4445
"tests:android:test:jacoco-report": "cd tests/android && ./gradlew jacocoAndroidTestReport",
4546
"tests:ios:build": "cd tests && yarn detox build --configuration ios.sim.debug",
4647
"tests:ios:build:release": "cd tests && yarn detox build --configuration ios.sim.release",
48+
"tests:ios:manual": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ yarn react-native run-ios",
4749
"tests:ios:test": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 yarn detox test --configuration ios.sim.debug --loglevel warn",
4850
"tests:ios:test:release": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 yarn detox test --configuration ios.sim.release --loglevel warn",
4951
"tests:ios:test:debug": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 yarn detox test --configuration ios.sim.debug --loglevel warn --inspect",
@@ -53,11 +55,9 @@
5355
"tests:ios:pod:install": "cd tests && rm -f ios/Podfile.lock && rm -rf ios/ReactNativeFirebaseDemo.xcworkspace && cd ios && pod install",
5456
"tests:macos:build": "cd tests && yarn build:macos",
5557
"tests:macos:pod:install": "cd tests && rm -f macos/Podfile.lock && cd macos && pod install",
58+
"tests:macos:manual": "cd tests && yarn react-native run-macos",
5659
"tests:macos:test-cover": "cd tests && npx jet --target=macos --coverage",
57-
"format:markdown": "prettier --write \"docs/**/*.md\"",
58-
"example:app:bundler": "cd tests && yarn react-native start --config ./test-app/metro.config.js --reset-cache",
59-
"example:app:run:ios": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ yarn react-native run-ios",
60-
"example:app:run:android": "cd tests && yarn react-native run-android"
60+
"format:markdown": "prettier --write \"docs/**/*.md\""
6161
},
6262
"devDependencies": {
6363
"@babel/core": "^7.28.3",

tests/app.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
*
1717
*/
1818

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

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

24-
import { LocalTests } from './local-test-component';
24+
import { TestComponents } from './local-tests';
2525

2626
const platformSupportedModules = [];
2727

@@ -67,6 +67,9 @@ ErrorUtils.setGlobalHandler((err, isFatal) => {
6767
});
6868

6969
function loadTests(_) {
70+
// this will only execute if Jet executes
71+
// ...so manual tests will not have this setup - emulators etc
72+
// ...that allows them the freedom to define their own test environment
7073
describe('React Native Firebase', function () {
7174
if (!globalThis.RNFBDebug) {
7275
// Only retry tests if not debugging or hunting deprecated API usage locally,
@@ -239,13 +242,28 @@ function loadTests(_) {
239242
}
240243

241244
function App() {
245+
const [showManualTestPicker, setShowManualTestPicker] = useState(false);
246+
247+
if (showManualTestPicker) {
248+
return (
249+
<>
250+
<StatusBar hidden />
251+
<View style={styles.container}>
252+
<View style={styles.hardRule} />
253+
<Button title="Hide Manual Tests" onPress={() => setShowManualTestPicker(false)} />
254+
<View style={styles.hardRule} />
255+
<TestComponents />
256+
</View>
257+
</>
258+
);
259+
}
260+
242261
return (
243262
<>
244263
<StatusBar hidden />
245264
<View style={styles.container}>
246265
<View style={styles.hardRule} />
247-
<Text>Local Manual Tests:</Text>
248-
<LocalTests />
266+
<Button title="Show Manual Tests" onPress={() => setShowManualTestPicker(true)} />
249267
<View style={styles.hardRule} />
250268
<Text>Automated Tests:</Text>
251269
<JetProvider tests={loadTests}>

tests/local-test-component.jsx

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/local-tests/.gitignore

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/test-app/examples/ai/ai.js renamed to tests/local-tests/ai/ai.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
/* eslint-disable no-console */
12
import React, { useState } from 'react';
2-
import { AppRegistry, Button, View, Text, Pressable } from 'react-native';
3+
import { Button, View, Text, Pressable } from 'react-native';
34

45
import { getApp } from '@react-native-firebase/app';
56
import { getAI, getGenerativeModel, Schema } from '@react-native-firebase/ai';
@@ -43,7 +44,7 @@ function OptionSelector({ selectedOption, setSelectedOption }) {
4344
);
4445
}
4546

46-
function App() {
47+
export function AITestComponent() {
4748
const [selectedOption, setSelectedOption] = useState('image');
4849
const getMediaDetails = option => {
4950
switch (option) {
@@ -242,7 +243,7 @@ function App() {
242243
// This function calls a hypothetical external API that returns
243244
// a collection of weather information for a given location on a given date.
244245
// `location` is an object of the form { city: string, state: string }
245-
async function fetchWeather({ location, date }) {
246+
async function fetchWeather({ _location, _date }) {
246247
// For demo purposes, this hypothetical response is hardcoded here in the expected format.
247248
return {
248249
temperature: 38,
@@ -324,5 +325,3 @@ function App() {
324325
</View>
325326
);
326327
}
327-
328-
AppRegistry.registerComponent('testing', () => App);

tests/test-app/examples/database/index.js renamed to tests/local-tests/database/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { AppRegistry, Button, Text, View } from 'react-native';
2+
import { Button, Text, View } from 'react-native';
33

44
// import firebase, { utils } from '@react-native-firebase/app';
55
import {
@@ -15,7 +15,7 @@ import {
1515

1616
connectDatabaseEmulator(getDatabase(), '127.0.0.1', 9000);
1717

18-
function App() {
18+
export function DatabaseOnChildMovedTest() {
1919
return (
2020
<View>
2121
<Text>text text text</Text>
@@ -56,5 +56,3 @@ function App() {
5656
</View>
5757
);
5858
}
59-
60-
AppRegistry.registerComponent('testing', () => App);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* eslint-disable no-console */
2+
import React, { useEffect } from 'react';
3+
import { Button, Text, View } from 'react-native';
4+
5+
import '@react-native-firebase/app';
6+
import {
7+
collection,
8+
doc,
9+
setDoc,
10+
getFirestore,
11+
onSnapshotsInSync,
12+
} from '@react-native-firebase/firestore';
13+
14+
export function FirestoreOnSnapshotInSyncTest() {
15+
let unsubscribe;
16+
17+
const subscribe = () => {
18+
if (unsubscribe) {
19+
console.log('already subscribed');
20+
return;
21+
}
22+
unsubscribe = onSnapshotsInSync(getFirestore(), () => {
23+
console.log('snapshots are in sync.');
24+
});
25+
};
26+
useEffect(() => {
27+
subscribe();
28+
}, []);
29+
30+
async function addDocument() {
31+
console.log('adding a document');
32+
await setDoc(doc(collection(getFirestore(), 'flutter-tests'), 'one'), { foo: 'bar' });
33+
console.log('done adding a document');
34+
}
35+
36+
return (
37+
<View>
38+
<Text>React Native Firebase</Text>
39+
<Text>onSnapshotsInSync API</Text>
40+
<Button
41+
title="add document"
42+
onPress={async () => {
43+
try {
44+
addDocument();
45+
} catch (e) {
46+
console.log('Add document failed', e);
47+
}
48+
}}
49+
/>
50+
<Button
51+
title="unsubscribe to snapshot in sync"
52+
onPress={() => {
53+
try {
54+
unsubscribe();
55+
unsubscribe = undefined;
56+
} catch (e) {
57+
console.log('Unsubscribe failed: ', e);
58+
}
59+
}}
60+
/>
61+
<Button
62+
title="subscribe to snapshot in sync"
63+
onPress={() => {
64+
try {
65+
subscribe();
66+
} catch (e) {
67+
console.log('Subscribe failed: ', e);
68+
}
69+
}}
70+
/>
71+
</View>
72+
);
73+
}

tests/local-tests/index.example.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/local-tests/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* eslint-disable react/react-in-jsx-scope */
2+
import { Button } from 'react-native';
3+
4+
import { useState } from 'react';
5+
6+
// import your components from your local-tests jsx file here...
7+
import { CrashTestComponent } from './crash-test';
8+
import { AITestComponent } from './ai/ai';
9+
import { DatabaseOnChildMovedTest } from './database';
10+
import { FirestoreOnSnapshotInSyncTest } from './firestore/onSnapshotInSync';
11+
import { VertexAITestComponent } from './vertexai/vertexai';
12+
13+
const testComponents = {
14+
// List your imported components here...
15+
'Crashlytics Test Crash': CrashTestComponent,
16+
'AI Generation Example': AITestComponent,
17+
'Database onChildMoved Test': DatabaseOnChildMovedTest,
18+
'Firestore onSnapshotInSync Test': FirestoreOnSnapshotInSyncTest,
19+
'VertexAI Generation Example': VertexAITestComponent,
20+
};
21+
22+
export function TestComponents() {
23+
const [currentTestTitle, setCurrentTestTitle] = useState(undefined);
24+
25+
if (currentTestTitle) {
26+
const CurrentTest = testComponents[currentTestTitle];
27+
return (
28+
<>
29+
<Button title={`Hide ${currentTestTitle}`} onPress={() => setCurrentTestTitle(undefined)} />
30+
<CurrentTest />
31+
</>
32+
);
33+
}
34+
35+
return Object.keys(testComponents).map((testTitle, index) => {
36+
return (
37+
<Button
38+
key={index}
39+
title={`Show ${testTitle}`}
40+
onPress={() => setCurrentTestTitle(testTitle)}
41+
/>
42+
);
43+
});
44+
}

0 commit comments

Comments
 (0)