Skip to content

Commit 8c4626c

Browse files
committed
Run node tests in test app
1 parent fd353ae commit 8c4626c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

apps/test-app/App.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "mocha-remote-react-native";
1010

1111
import { suites as nodeAddonExamplesSuites } from "@react-native-node-api/node-addon-examples";
12+
import { suites as nodeTestsSuites } from "@react-native-node-api/node-tests";
1213

1314
function describeIf(
1415
condition: boolean,
@@ -21,12 +22,14 @@ function describeIf(
2122
type Context = {
2223
allTests?: boolean;
2324
nodeAddonExamples?: boolean;
25+
nodeTests?: boolean;
2426
ferricExample?: boolean;
2527
};
2628

2729
function loadTests({
2830
allTests = false,
2931
nodeAddonExamples = allTests,
32+
nodeTests = allTests,
3033
ferricExample = allTests,
3134
}: Context) {
3235
describeIf(nodeAddonExamples, "Node Addon Examples", () => {
@@ -46,6 +49,16 @@ function loadTests({
4649
}
4750
});
4851

52+
describeIf(nodeTests, "Node Tests", () => {
53+
for (const [suiteName, examples] of Object.entries(nodeTestsSuites)) {
54+
describe(suiteName, () => {
55+
for (const [exampleName, requireTest] of Object.entries(examples)) {
56+
it(exampleName, requireTest);
57+
}
58+
});
59+
}
60+
});
61+
4962
describeIf(ferricExample, "ferric-example", () => {
5063
it("exports a callable sum function", () => {
5164
/* eslint-disable-next-line @typescript-eslint/no-require-imports -- TODO: Determine why a dynamic import doesn't work on Android */

apps/test-app/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"test:android": "mocha-remote --exit-on-error -- concurrently --kill-others-on-fail --passthrough-arguments npm:metro 'npm:android -- {@}' --",
1111
"test:android:allTests": "MOCHA_REMOTE_CONTEXT=allTests npm run test:android -- ",
1212
"test:android:nodeAddonExamples": "MOCHA_REMOTE_CONTEXT=nodeAddonExamples npm run test:android -- ",
13+
"test:android:nodeTests": "MOCHA_REMOTE_CONTEXT=nodeTests npm run test:android -- ",
1314
"test:android:ferricExample": "MOCHA_REMOTE_CONTEXT=ferricExample npm run test:android -- ",
1415
"test:ios": "mocha-remote --exit-on-error -- concurrently --passthrough-arguments --kill-others-on-fail npm:metro 'npm:ios -- {@}' --",
1516
"test:ios:allTests": "MOCHA_REMOTE_CONTEXT=allTests npm run test:ios -- ",
1617
"test:ios:nodeAddonExamples": "MOCHA_REMOTE_CONTEXT=nodeAddonExamples npm run test:ios -- ",
18+
"test:ios:nodeTests": "MOCHA_REMOTE_CONTEXT=nodeTests npm run test:ios -- ",
1719
"test:ios:ferricExample": "MOCHA_REMOTE_CONTEXT=ferricExample npm run test:ios -- "
1820
},
1921
"dependencies": {
@@ -23,6 +25,8 @@
2325
"@react-native-community/cli": "^18.0.0",
2426
"@react-native-community/cli-platform-android": "^18.0.0",
2527
"@react-native-community/cli-platform-ios": "^18.0.0",
28+
"@react-native-node-api/node-addon-examples": "*",
29+
"@react-native-node-api/node-tests": "*",
2630
"@react-native/babel-preset": "0.79.0",
2731
"@react-native/metro-config": "0.79.0",
2832
"@react-native/typescript-config": "0.79.0",
@@ -36,7 +40,6 @@
3640
"mocha-remote-react-native": "^1.13.2",
3741
"react": "19.0.0",
3842
"react-native": "0.79.5",
39-
"react-native-node-addon-examples": "*",
4043
"react-native-node-api": "*",
4144
"react-native-test-app": "^4.3.3"
4245
}

packages/node-tests/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
3+
export const suites: Record<string, Record<string, () => void>> = {
4+
"2_function_arguments": {
5+
test: () =>
6+
require("../tests/js-native-api/2_function_arguments/test.bundle.js"),
7+
},
8+
};

0 commit comments

Comments
 (0)