From 3230a82c2902eed1a2b8d4291cf61d5df94eeaff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Thu, 19 Jun 2025 19:59:59 +0200 Subject: [PATCH 01/10] Add mocha-remote to test-app --- apps/test-app/App.tsx | 93 ++-- apps/test-app/package.json | 12 +- package-lock.json | 663 +++++++++++++++++++++++++- packages/node-addon-examples/index.js | 2 +- 4 files changed, 725 insertions(+), 45 deletions(-) diff --git a/apps/test-app/App.tsx b/apps/test-app/App.tsx index a1aad6be..48a11861 100644 --- a/apps/test-app/App.tsx +++ b/apps/test-app/App.tsx @@ -1,56 +1,73 @@ import React from "react"; -import { StyleSheet, Text, View, Button } from "react-native"; +import { StyleSheet, View, SafeAreaView } from "react-native"; -/* eslint-disable @typescript-eslint/no-require-imports -- We're using require to defer crashes */ +import { + MochaRemoteProvider, + ConnectionText, + StatusEmoji, + StatusText, +} from "mocha-remote-react-native"; -// import { requireNodeAddon } from "react-native-node-api"; -import nodeAddonExamples from "react-native-node-addon-examples"; -// import * as ferricExample from "ferric-example"; +import nodeAddonExamples from "@react-native-node-api/node-addon-examples"; -function App(): React.JSX.Element { +function loadTests() { + for (const [suiteName, examples] of Object.entries(nodeAddonExamples)) { + describe(suiteName, () => { + for (const [exampleName, requireExample] of Object.entries(examples)) { + it(exampleName, () => { + requireExample(); + }); + } + }); + } + + describe("ferric-example", () => { + it("exports a callable sum function", () => { + // eslint-disable-next-line @typescript-eslint/no-require-imports + const exampleAddon = require("ferric-example"); + const result = exampleAddon.sum(1, 3); + if (result !== 4) { + throw new Error(`Expected 1 + 3 to equal 4, but got ${result}`); + } + }); + }); +} + +export default function App() { return ( - - React Native Node-API Modules - {Object.entries(nodeAddonExamples).map(([suiteName, examples]) => ( - - {suiteName} - {Object.entries(examples).map(([exampleName, requireExample]) => ( -