|
1 | 1 | import React from "react";
|
2 |
| -import { StyleSheet, Text, View, Button } from "react-native"; |
| 2 | +import { StyleSheet, View, SafeAreaView } from "react-native"; |
3 | 3 |
|
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"; |
5 | 10 |
|
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"; |
9 | 12 |
|
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() { |
11 | 37 | 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} /> |
24 | 44 | </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> |
36 | 47 | );
|
37 | 48 | }
|
38 | 49 |
|
39 | 50 | const styles = StyleSheet.create({
|
40 | 51 | container: {
|
41 | 52 | flex: 1,
|
42 |
| - justifyContent: "center", |
| 53 | + backgroundColor: "#fff", |
| 54 | + }, |
| 55 | + statusContainer: { |
| 56 | + flex: 1, |
43 | 57 | alignItems: "center",
|
| 58 | + justifyContent: "center", |
44 | 59 | },
|
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", |
50 | 64 | },
|
51 |
| - title: { |
| 65 | + statusText: { |
52 | 66 | fontSize: 20,
|
| 67 | + margin: 20, |
| 68 | + textAlign: "center", |
| 69 | + }, |
| 70 | + connectionText: { |
| 71 | + textAlign: "center", |
53 | 72 | },
|
54 | 73 | });
|
55 |
| - |
56 |
| -export default App; |
|
0 commit comments