Skip to content

Commit c3391f3

Browse files
committed
feat: replace custom e2e test with react-native-harness ones
1 parent c91f0a5 commit c3391f3

14 files changed

Lines changed: 1218 additions & 701 deletions

.github/workflows/tests.yaml

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,84 @@ jobs:
9595
path: react-native-hcaptcha
9696
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
9797
with:
98-
node-version: 22.11.0
99-
- uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
98+
node-version: 22
99+
- if: matrix.platform == 'android'
100+
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
100101
with:
101102
java-version: 17
102103
distribution: adopt
103-
- if: contains(matrix.os, 'macos')
104+
- if: matrix.platform == 'ios'
104105
run: sudo xcode-select -s /Applications/Xcode_16.4.app
105-
- run: |
106-
npm run example -- --pm ${{ matrix.pm }}
106+
- run: npm run example -- --pm ${{ matrix.pm }}
107107
working-directory: react-native-hcaptcha
108108
env:
109109
YARN_ENABLE_IMMUTABLE_INSTALLS: false
110110
- id: rn-version
111111
working-directory: react-native-hcaptcha-example
112112
run: |
113-
RN_VERSION=$(cat package.json | jq ".dependencies.\"react-native\"" -r)
113+
RN_VERSION=$(jq -r ".dependencies.\"react-native\"" package.json)
114114
echo "value=${RN_VERSION}" >> $GITHUB_OUTPUT
115-
- run: cat package.json
116-
working-directory: react-native-hcaptcha-example
117115
- run: yarn test --config ./jest.config.js
118116
working-directory: react-native-hcaptcha-example
119117
- run: npx react-native build-${{ matrix.platform }}
120118
working-directory: react-native-hcaptcha-example
121119
- run: npx --yes check-peer-dependencies --yarn --runOnlyOnRootDependencies
122120
working-directory: react-native-hcaptcha-example
123121

122+
e2e:
123+
needs: build
124+
permissions:
125+
contents: read
126+
runs-on: ${{ matrix.os }}
127+
concurrency:
128+
group: 'e2e-${{ matrix.platform }}-${{ github.head_ref || github.ref_name }}'
129+
cancel-in-progress: true
130+
strategy:
131+
fail-fast: false
132+
matrix:
133+
include:
134+
- os: ubuntu-latest
135+
platform: android
136+
- os: macos-latest
137+
platform: ios
138+
steps:
139+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
140+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
141+
with:
142+
node-version: 22
143+
- if: matrix.platform == 'android'
144+
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
145+
with:
146+
java-version: 17
147+
distribution: adopt
148+
- run: npm install
149+
- name: Generate E2E host app
150+
run: npm run test:e2e:setup -- --pm npm --platform ${{ matrix.platform }}
151+
152+
- if: matrix.platform == 'android'
153+
name: Run Android E2E tests
154+
uses: hCaptcha/hcaptcha-android-sdk/.github/actions/android-emulator-run@dc2e0fc978424322c977b68ae06f8dd54e571e22
155+
with:
156+
target: google_apis
157+
api-level: '34'
158+
profile: pixel_7
159+
script: npm run test:e2e:android
160+
161+
- if: matrix.platform == 'ios'
162+
name: Boot iOS simulator
163+
run: xcrun simctl bootstatus "iPhone 16" -b
164+
165+
- if: matrix.platform == 'ios'
166+
name: Run iOS E2E tests
167+
run: npm run test:e2e:ios
168+
169+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
170+
if: always()
171+
with:
172+
name: e2e-results-${{ matrix.platform }}
173+
path: __e2e__/__image_snapshots__/
174+
retention-days: 14
175+
124176
create-an-issue:
125177
permissions:
126178
contents: read

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
node_modules/*
22
yarn.lock
3+
.DS_Store
34

45
# Reassure performance testing files
56
.reassure/
67
output/
8+
9+
# Generated E2E host app
10+
__e2e__/host/
47.3 KB
Loading
49 KB
Loading
104 KB
Loading
105 KB
Loading

__e2e__/darkTheme.harness.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { describe, test, render, expect } from 'react-native-harness';
2+
import { screen } from '@react-native-harness/ui';
3+
import React from 'react';
4+
import { StyleSheet, View } from 'react-native';
5+
6+
import Hcaptcha from '@hcaptcha/react-native-hcaptcha/Hcaptcha.js';
7+
8+
const siteKey = '10000000-ffff-ffff-ffff-000000000001';
9+
const baseUrl = 'https://hcaptcha.com';
10+
11+
const WEBVIEW_LOAD_MS = 10000;
12+
13+
const WidgetFixture = ({ theme }) => (
14+
<View style={styles.container}>
15+
<View style={styles.widgetFrame}>
16+
<Hcaptcha
17+
siteKey={siteKey}
18+
size="normal"
19+
theme={theme}
20+
url={baseUrl}
21+
style={styles.widget}
22+
onMessage={() => {}}
23+
/>
24+
</View>
25+
</View>
26+
);
27+
28+
const styles = StyleSheet.create({
29+
container: {
30+
flex: 1,
31+
justifyContent: 'center',
32+
alignItems: 'center',
33+
backgroundColor: '#eef2ff',
34+
},
35+
widgetFrame: {
36+
width: 360,
37+
height: 118,
38+
overflow: 'hidden',
39+
borderRadius: 18,
40+
borderWidth: 1,
41+
borderColor: '#cbd5e1',
42+
backgroundColor: '#ffffff',
43+
},
44+
widget: {
45+
flex: 1,
46+
height: '100%',
47+
},
48+
});
49+
50+
describe('hCaptcha theme rendering', () => {
51+
test('light widget matches baseline', async () => {
52+
await render(<WidgetFixture theme="light" />, { timeout: WEBVIEW_LOAD_MS });
53+
await new Promise((r) => setTimeout(r, WEBVIEW_LOAD_MS));
54+
55+
const screenshot = await screen.screenshot();
56+
await expect(screenshot).toMatchImageSnapshot({
57+
name: 'hcaptcha-light',
58+
threshold: 0.15,
59+
failureThreshold: 5,
60+
failureThresholdType: 'percent',
61+
});
62+
});
63+
64+
test('dark widget matches baseline', async () => {
65+
await render(<WidgetFixture theme="dark" />, { timeout: WEBVIEW_LOAD_MS });
66+
await new Promise((r) => setTimeout(r, WEBVIEW_LOAD_MS));
67+
68+
const screenshot = await screen.screenshot();
69+
await expect(screenshot).toMatchImageSnapshot({
70+
name: 'hcaptcha-dark',
71+
threshold: 0.15,
72+
failureThreshold: 5,
73+
failureThresholdType: 'percent',
74+
});
75+
});
76+
});

__e2e__/jest.harness.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
preset: 'react-native-harness',
3+
testMatch: ['<rootDir>/__e2e__/**/*.harness.{js,ts,tsx}'],
4+
};

0 commit comments

Comments
 (0)