diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c9708b2e..5c159e4d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,3 +1,9 @@ +name: Check + +env: + # Version here should match the one in React Native template and packages/cmake-rn/src/cli.ts + NDK_VERSION: 27.1.12297006 + on: push: branches: @@ -9,41 +15,17 @@ concurrency: cancel-in-progress: true jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: lts/jod - - run: npm ci - - run: npm run lint - test-simple: - name: Run tests which doesn't require MacOS - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: lts/jod - - run: npm ci - - run: npm run build - - run: npm test --workspace gyp-to-cmake --workspace cmake-rn --workspace react-native-node-api - test-windows: - name: Run tests on Windows - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: lts/jod - - run: npm ci - - run: npm run build - - run: npm test --workspace gyp-to-cmake --workspace cmake-rn --workspace react-native-node-api + test: + strategy: + fail-fast: false + matrix: + runner: + - ubuntu-latest + variant: + - android-tests - test-macos: - name: Run tests which requires MacOS - runs-on: macos-latest + name: Test (${{ matrix.variant }} on ${{ matrix.runner }}) + runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -56,11 +38,45 @@ jobs: distribution: "temurin" - name: Setup Android SDK uses: android-actions/setup-android@v3 - # Version here should match the one in React Native template and packages/cmake-rn/src/cli.ts - - run: sdkmanager --install "ndk;27.1.12297006" + with: + packages: tools platform-tools ndk;${{ env.NDK_VERSION }} - run: npm ci - - run: npm run build - - run: npm run copy-node-api-headers --workspace react-native-node-api - - run: npm run build-weak-node-api --workspace react-native-node-api - - run: npm run generate-weak-node-api-injector --workspace react-native-node-api - - run: npm test --workspace @react-native-node-api/node-addon-examples + - name: Setup Android Emulator cache + if: matrix.variant == 'android-tests' + uses: actions/cache@v4 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: ${{ runner.os }}-avd-29 + # See https://github.com/marketplace/actions/android-emulator-runner#running-hardware-accelerated-emulators-on-linux-runners + - name: Enable KVM group perms + if: matrix.runner == 'ubuntu-latest' && matrix.variant == 'android-tests' + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + - name: Run tests (Android) + if: matrix.variant == 'android-tests' + timeout-minutes: 75 + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 29 + force-avd-creation: false + emulator-options: -no-snapshot-save -no-metrics -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: true + arch: ${{ runner.os == 'macOS' && 'arm64-v8a' || 'x86' }} + ndk: ${{ env.NDK_VERSION }} + cmake: 3.22.1 + working-directory: apps/test-app + script: | + # Setup port forwarding to Mocha Remote + adb reverse tcp:8090 tcp:8090 + # Uninstall the app if already in the snapshot (unlikely but could result in a signature mismatch failure) + adb uninstall com.microsoft.reacttestapp || true + # Build, install and run the app + npm run test:android + # Print some debug info + sleep 5 + ps aux 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]) => ( -