|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { describe, it } from "node:test"; |
| 3 | +import cp from "node:child_process"; |
| 4 | +import path from "node:path"; |
| 5 | + |
| 6 | +const PACKAGE_ROOT = path.join(__dirname, "../.."); |
| 7 | +const MONOREPO_ROOT = path.join(PACKAGE_ROOT, "../.."); |
| 8 | +const TEST_APP_ANDROID_PATH = path.join(MONOREPO_ROOT, "apps/test-app/android"); |
| 9 | + |
| 10 | +describe( |
| 11 | + "Gradle tasks", |
| 12 | + // Skipping these tests by default, as they download a lot and takes a long time |
| 13 | + { skip: process.env.ENABLE_GRADLE_TESTS !== "true" }, |
| 14 | + () => { |
| 15 | + describe("checkHermesOverride task", () => { |
| 16 | + it("should fail if REACT_NATIVE_OVERRIDE_HERMES_DIR is not set", () => { |
| 17 | + const { status, stdout, stderr } = cp.spawnSync( |
| 18 | + "sh", |
| 19 | + ["gradlew", "react-native-node-api:checkHermesOverride"], |
| 20 | + { |
| 21 | + cwd: TEST_APP_ANDROID_PATH, |
| 22 | + env: { |
| 23 | + ...process.env, |
| 24 | + REACT_NATIVE_OVERRIDE_HERMES_DIR: undefined, |
| 25 | + }, |
| 26 | + encoding: "utf-8", |
| 27 | + }, |
| 28 | + ); |
| 29 | + |
| 30 | + assert.notEqual(status, 0, `Expected failure: ${stdout} ${stderr}`); |
| 31 | + assert.match( |
| 32 | + stderr, |
| 33 | + /React Native Node-API needs a custom version of Hermes with Node-API enabled/, |
| 34 | + ); |
| 35 | + assert.match( |
| 36 | + stderr, |
| 37 | + /Run the following in your terminal, to clone Hermes and instruct React Native to use it/, |
| 38 | + ); |
| 39 | + assert.match( |
| 40 | + stderr, |
| 41 | + /export REACT_NATIVE_OVERRIDE_HERMES_DIR=`npx react-native-node-api vendor-hermes --silent --force`/, |
| 42 | + ); |
| 43 | + assert.match( |
| 44 | + stderr, |
| 45 | + /And follow this guide to build React Native from source/, |
| 46 | + ); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + describe("linkNodeApiModules task", () => { |
| 51 | + it("should call the CLI to autolink", () => { |
| 52 | + const { status, stdout, stderr } = cp.spawnSync( |
| 53 | + "sh", |
| 54 | + ["gradlew", "react-native-node-api:linkNodeApiModules"], |
| 55 | + { |
| 56 | + cwd: TEST_APP_ANDROID_PATH, |
| 57 | + encoding: "utf-8", |
| 58 | + }, |
| 59 | + ); |
| 60 | + |
| 61 | + assert.equal(status, 0, `Expected success: ${stdout} ${stderr}`); |
| 62 | + assert.match(stdout, /Auto-linking Node-API modules/); |
| 63 | + }); |
| 64 | + }); |
| 65 | + }, |
| 66 | +); |
0 commit comments