Skip to content

Commit 2934349

Browse files
committed
refactor: update test imports and assertions to use react-native-harness
1 parent 9126ff4 commit 2934349

16 files changed

Lines changed: 362 additions & 175 deletions
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Test Harness Android
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/test-harness-android.yml"
7+
- "example/android/**"
8+
- "example/src/tests/**"
9+
- "example/__tests__/**"
10+
- "example/rn-harness.config.mjs"
11+
- "example/jest.config.js"
12+
- "package/cpp/**"
13+
- "package/android/**"
14+
- "**/bun.lock"
15+
- "**/react-native.config.js"
16+
- "**/nitro.json"
17+
18+
env:
19+
TARGET_ANDROID_ARCH: x86_64
20+
21+
jobs:
22+
test:
23+
name: Harness Tests (Android)
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@v6
28+
- uses: oven-sh/setup-bun@v2
29+
30+
- name: Setup JDK 17
31+
uses: actions/setup-java@v5
32+
with:
33+
distribution: "zulu"
34+
java-version: 17
35+
36+
- name: Enable KVM group perms
37+
run: |
38+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
39+
sudo udevadm control --reload-rules
40+
sudo udevadm trigger --name-match=kvm
41+
42+
- name: Install dependencies (bun)
43+
run: bun install
44+
45+
- name: Run react-native-harness on Android
46+
uses: reactivecircus/android-emulator-runner@v2
47+
with:
48+
api-level: 35
49+
arch: x86_64
50+
avd-name: Pixel_8_API_35
51+
working-directory: example/android
52+
script: >-
53+
./gradlew :app:installDebug --no-daemon
54+
-PreactNativeArchitectures=${{ env.TARGET_ANDROID_ARCH }}
55+
&& bun --cwd .. run test:harness:android
56+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Test Harness iOS
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/test-harness-ios.yml"
7+
- "example/ios/**"
8+
- "example/src/tests/**"
9+
- "example/__tests__/**"
10+
- "example/rn-harness.config.mjs"
11+
- "example/jest.config.js"
12+
- "package/cpp/**"
13+
- "package/ios/**"
14+
- "**/Podfile.lock"
15+
- "**/*.podspec"
16+
- "**/react-native.config.js"
17+
- "**/nitro.json"
18+
- "**/bun.lock"
19+
20+
jobs:
21+
test:
22+
name: Harness Tests (iOS)
23+
runs-on: macOS-26
24+
25+
steps:
26+
- uses: actions/checkout@v6
27+
- uses: oven-sh/setup-bun@v2
28+
29+
- name: Setup Ruby (bundle)
30+
uses: ruby/setup-ruby@v1
31+
with:
32+
ruby-version: 3.3.0
33+
bundler-cache: true
34+
working-directory: example
35+
36+
- name: Select Xcode 26.2
37+
run: sudo xcode-select -s "/Applications/Xcode_26.2.app/Contents/Developer"
38+
39+
- name: Install Pods
40+
working-directory: example
41+
run: bun pods
42+
43+
- name: Boot iOS Simulator
44+
run: |
45+
xcrun simctl boot "iPhone 17 Pro (26.2)" || true
46+
xcrun simctl bootstatus booted -b
47+
48+
- name: Build and install debug app
49+
working-directory: example/ios
50+
run: |
51+
set -o pipefail
52+
xcodebuild \
53+
CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ \
54+
-derivedDataPath build -UseModernBuildSystem=YES \
55+
-workspace NitroSQLiteExample.xcworkspace \
56+
-scheme NitroSQLiteExample \
57+
-sdk iphonesimulator \
58+
-configuration Debug \
59+
-destination 'platform=iOS Simulator,name=iPhone 17 Pro,OS=26.2' \
60+
ONLY_ACTIVE_ARCH=YES \
61+
install \
62+
CODE_SIGNING_ALLOWED=NO
63+
64+
- name: Run react-native-harness on iOS
65+
run: bun --cwd example run test:harness:ios
66+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { registerTypeORMUnitTests } from '../src/tests/unit'
2+
3+
registerTypeORMUnitTests()

example/__tests__/unit.harness.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { registerUnitTests } from '../src/tests/unit'
2+
3+
registerUnitTests()

example/jest.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
projects: [
3+
{
4+
displayName: "react-native-harness",
5+
preset: "react-native-harness",
6+
testMatch: [
7+
"**/__tests__/**/*.(test|spec|harness).(js|jsx|ts|tsx)",
8+
],
9+
},
10+
],
11+
};
12+

example/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"pods": "cd ios && bundle exec pod install",
1111
"typecheck": "tsc --noEmit",
1212
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
13-
"codegen": "bun react-native codegen"
13+
"codegen": "bun react-native codegen",
14+
"test:harness": "react-native-harness",
15+
"test:harness:android": "react-native-harness --harnessRunner android",
16+
"test:harness:ios": "react-native-harness --harnessRunner ios"
1417
},
1518
"dependencies": {
1619
"@craftzdog/react-native-buffer": "^6.0.5",
@@ -49,6 +52,11 @@
4952
"@types/node": "^22.7.4",
5053
"@types/react": "^19.1.1",
5154
"@types/react-test-renderer": "^19.1.0",
55+
"@react-native-harness/cli": "1.0.0-alpha.21",
56+
"@react-native-harness/jest": "1.0.0-alpha.21",
57+
"@react-native-harness/platform-android": "1.0.0-alpha.21",
58+
"@react-native-harness/platform-apple": "1.0.0-alpha.21",
59+
"react-native-harness": "1.0.0-alpha.21",
5260
"mocha": "^10.1.0",
5361
"postinstall-postinstall": "^2.1.0",
5462
"react-test-renderer": "19.1.1"

example/rn-harness.config.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
androidPlatform,
3+
androidEmulator,
4+
} from "@react-native-harness/platform-android";
5+
import {
6+
applePlatform,
7+
appleSimulator,
8+
} from "@react-native-harness/platform-apple";
9+
10+
const config = {
11+
entryPoint: "./index.js",
12+
appRegistryComponentName: "NitroSQLiteExample",
13+
14+
runners: [
15+
androidPlatform({
16+
name: "android",
17+
device: androidEmulator("Pixel_8_API_35"),
18+
bundleId: "com.margelo.rnnitrosqlite.example",
19+
}),
20+
applePlatform({
21+
name: "ios",
22+
device: appleSimulator("iPhone 17 Pro", "26.2"),
23+
bundleId: "com.margelo.rnnitrosqlite.example",
24+
}),
25+
],
26+
27+
defaultRunner: "android",
28+
bridgeTimeout: 120000,
29+
30+
resetEnvironmentBetweenTestFiles: true,
31+
unstable__skipAlreadyIncludedModules: false,
32+
};
33+
34+
export default config;
35+

example/src/tests/unit/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Chance } from 'chance'
22
import { NitroSQLiteError } from 'react-native-nitro-sqlite'
33
import { resetTestDb } from '../db'
4-
import chai from 'chai'
4+
import { expect as harnessExpect } from 'react-native-harness'
55

66
export const TEST_ERROR_CODES = {
77
EXPECT_NITRO_SQLITE_ERROR: 'Should have thrown a valid NitroSQLiteError',
@@ -15,7 +15,7 @@ export function isNitroSQLiteError(e: unknown): e is NitroSQLiteError {
1515
return e instanceof NitroSQLiteError
1616
}
1717

18-
export const expect = chai.expect
18+
export const expect = harnessExpect
1919
export const chance = new Chance()
2020

2121
export function setupTestDb() {

example/src/tests/unit/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe } from '../MochaRNAdapter'
1+
import { beforeEach, describe } from 'react-native-harness'
22
import { setupTestDb } from './common'
33
import registerExecuteUnitTests from './specs/operations/execute.spec'
44
import registerTransactionUnitTests from './specs/operations/transaction.spec'

0 commit comments

Comments
 (0)