Skip to content

Commit 3f948eb

Browse files
authored
feat: replace custom CLI with Jest wrapper (#16)
This pull request fully migrates React Native Harness from a custom CLI to a Jest-based CLI.
1 parent 0ffd0ce commit 3f948eb

File tree

29 files changed

+346
-702
lines changed

29 files changed

+346
-702
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
146146
script: |
147147
adb install -r "./app/build/outputs/apk/debug/app-debug.apk"
148-
pnpm nx run @react-native-harness/${{ matrix.app }}:start --args="test android"
148+
pnpm nx run @react-native-harness/${{ matrix.app }}:start --args="--harnessRunner android"
149149
150150
e2e-ios:
151151
name: E2E iOS - ${{ matrix.app }}
@@ -237,4 +237,18 @@ jobs:
237237
238238
- name: Run E2E tests
239239
run: |
240-
pnpm nx run @react-native-harness/${{ matrix.app }}:start --args="test ios"
240+
pnpm nx run @react-native-harness/${{ matrix.app }}:start --args="--harnessRunner ios"
241+
242+
- name: Capture simulator screenshot on failure
243+
if: failure()
244+
run: |
245+
mkdir -p screenshots
246+
xcrun simctl io booted screenshot screenshots/ios-failure-${{ matrix.app }}.png
247+
248+
- name: Upload screenshot artifact
249+
if: failure()
250+
uses: actions/upload-artifact@v4
251+
with:
252+
name: ios-failure-screenshot-${{ matrix.app }}
253+
path: screenshots/ios-failure-${{ matrix.app }}.png
254+
retention-days: 7

apps/playground/rn-harness.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const config = {
22
entryPoint: './src/main.tsx',
33
appRegistryComponentName: 'Playground',
4-
include: ['./src/__tests__/**/*'],
54

65
runners: [
76
{

apps/playground/src/__tests__/mocking/modules.harness.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,26 @@ describe('Module mocking', () => {
5151
// Get the actual react-native module
5252
const actualRN = requireActual('react-native');
5353

54-
// Return the actual module but with Platform mocked
55-
return {
56-
...actualRN,
57-
Platform: {
58-
OS: 'mockOS',
59-
Version: 999,
60-
select: fn().mockImplementation((options: Record<string, any>) => {
61-
return options.mockOS || options.default;
62-
}),
63-
isPad: false,
64-
isTesting: true,
65-
},
54+
// Copy without invoking getters to avoid triggering lazy initialization
55+
const proto = Object.getPrototypeOf(actualRN);
56+
const descriptors = Object.getOwnPropertyDescriptors(actualRN);
57+
58+
const mockedRN = Object.create(proto, descriptors);
59+
const mockedPlatform = {
60+
OS: 'mockOS',
61+
Version: 999,
62+
select: fn().mockImplementation((options: Record<string, any>) => {
63+
return options.mockOS || options.default;
64+
}),
65+
isPad: false,
66+
isTesting: true,
6667
};
68+
Object.defineProperty(mockedRN, 'Platform', {
69+
get() {
70+
return mockedPlatform;
71+
},
72+
});
73+
return mockedRN;
6774
};
6875

6976
mock('react-native', mockFactory);

packages/cli/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
"@react-native-harness/bridge": "workspace:*",
2525
"@react-native-harness/config": "workspace:*",
2626
"@react-native-harness/tools": "workspace:*",
27-
"commander": "^14.0.0",
28-
"glob": "^11.0.0",
2927
"tslib": "^2.3.0"
3028
},
3129
"devDependencies": {
32-
"@types/node": "18.16.9"
30+
"@types/node": "18.16.9",
31+
"jest-cli": "^30.2.0"
32+
},
33+
"peerDependencies": {
34+
"jest-cli": "*"
3335
},
3436
"license": "MIT"
3537
}

packages/cli/src/commands/test.ts

Lines changed: 0 additions & 232 deletions
This file was deleted.

packages/cli/src/discovery/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/cli/src/discovery/testDiscovery.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)