Skip to content

Commit bf747ca

Browse files
committed
Add mocha-remote to test-app
1 parent 2e957ad commit bf747ca

File tree

4 files changed

+725
-45
lines changed

4 files changed

+725
-45
lines changed

apps/test-app/App.tsx

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,73 @@
11
import React from "react";
2-
import { StyleSheet, Text, View, Button } from "react-native";
2+
import { StyleSheet, View, SafeAreaView } from "react-native";
33

4-
/* eslint-disable @typescript-eslint/no-require-imports -- We're using require to defer crashes */
4+
import {
5+
MochaRemoteProvider,
6+
ConnectionText,
7+
StatusEmoji,
8+
StatusText,
9+
} from "mocha-remote-react-native";
510

6-
// import { requireNodeAddon } from "react-native-node-api";
7-
import nodeAddonExamples from "react-native-node-addon-examples";
8-
// import * as ferricExample from "ferric-example";
11+
import nodeAddonExamples from "@react-native-node-api/node-addon-examples";
912

10-
function App(): React.JSX.Element {
13+
function loadTests() {
14+
for (const [suiteName, examples] of Object.entries(nodeAddonExamples)) {
15+
describe(suiteName, () => {
16+
for (const [exampleName, requireExample] of Object.entries(examples)) {
17+
it(exampleName, () => {
18+
requireExample();
19+
});
20+
}
21+
});
22+
}
23+
24+
describe("ferric-example", () => {
25+
it("exports a callable sum function", () => {
26+
// eslint-disable-next-line @typescript-eslint/no-require-imports
27+
const exampleAddon = require("ferric-example");
28+
const result = exampleAddon.sum(1, 3);
29+
if (result !== 4) {
30+
throw new Error(`Expected 1 + 3 to equal 4, but got ${result}`);
31+
}
32+
});
33+
});
34+
}
35+
36+
export default function App() {
1137
return (
12-
<View style={styles.container}>
13-
<Text style={styles.title}>React Native Node-API Modules</Text>
14-
{Object.entries(nodeAddonExamples).map(([suiteName, examples]) => (
15-
<View key={suiteName} style={styles.suite}>
16-
<Text>{suiteName}</Text>
17-
{Object.entries(examples).map(([exampleName, requireExample]) => (
18-
<Button
19-
key={exampleName}
20-
title={exampleName}
21-
onPress={requireExample}
22-
/>
23-
))}
38+
<MochaRemoteProvider tests={loadTests}>
39+
<SafeAreaView style={styles.container}>
40+
<ConnectionText style={styles.connectionText} />
41+
<View style={styles.statusContainer}>
42+
<StatusEmoji style={styles.statusEmoji} />
43+
<StatusText style={styles.statusText} />
2444
</View>
25-
))}
26-
<View key="ferric-example" style={styles.suite}>
27-
<Text>ferric-example</Text>
28-
<Button
29-
title={"Ferric Example: sum(1, 3)"}
30-
onPress={() =>
31-
console.log("1+3 = " + require("ferric-example").sum(1, 3))
32-
}
33-
/>
34-
</View>
35-
</View>
45+
</SafeAreaView>
46+
</MochaRemoteProvider>
3647
);
3748
}
3849

3950
const styles = StyleSheet.create({
4051
container: {
4152
flex: 1,
42-
justifyContent: "center",
53+
backgroundColor: "#fff",
54+
},
55+
statusContainer: {
56+
flex: 1,
4357
alignItems: "center",
58+
justifyContent: "center",
4459
},
45-
suite: {
46-
borderWidth: 1,
47-
width: "96%",
48-
margin: 10,
49-
padding: 10,
60+
statusEmoji: {
61+
fontSize: 30,
62+
margin: 30,
63+
textAlign: "center",
5064
},
51-
title: {
65+
statusText: {
5266
fontSize: 20,
67+
margin: 20,
68+
textAlign: "center",
69+
},
70+
connectionText: {
71+
textAlign: "center",
5372
},
5473
});
55-
56-
export default App;

apps/test-app/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
"private": true,
44
"version": "0.1.0",
55
"scripts": {
6-
"android": "react-native run-android",
6+
"start": "react-native start",
7+
"android": "react-native run-android --no-packager",
78
"build:android": "react-native bundle --entry-file index.js --platform android --dev true --bundle-output dist/main.android.jsbundle --assets-dest dist/res",
8-
"ios": "react-native run-ios",
9+
"ios": "react-native run-ios --no-packager",
910
"pod-install": "cd ios && pod install",
10-
"start": "react-native start"
11+
"test:android": "mocha-remote --exit-on-error -- concurrently npm:start npm:android",
12+
"test:ios": "mocha-remote --exit-on-error -- concurrently npm:start npm:ios"
1113
},
1214
"dependencies": {
1315
"@babel/core": "^7.26.10",
@@ -21,7 +23,11 @@
2123
"@react-native/typescript-config": "0.79.0",
2224
"@rnx-kit/metro-config": "^2.0.1",
2325
"@types/react": "^19.0.0",
26+
"concurrently": "^9.1.2",
2427
"ferric-example": "^0.1.0",
28+
"mocha": "^11.6.0",
29+
"mocha-remote-cli": "^1.13.1",
30+
"mocha-remote-react-native": "^1.13.1",
2531
"react": "19.0.0",
2632
"react-native": "0.79.1",
2733
"react-native-node-addon-examples": "*",

0 commit comments

Comments
 (0)