diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml
index 3d1853f..c472b37 100644
--- a/.github/workflows/tests.yaml
+++ b/.github/workflows/tests.yaml
@@ -1,11 +1,67 @@
name: CI
-on: push
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ workflow_dispatch:
+
+env:
+ TEST_APP_DEPS: react-native-modal react-native-webview expo-constants@^10.0.1 @unimodules/core @unimodules/react-native-adapter react-native-unimodules
+ TEST_APP_DEV_DEPS: typescript @babel/preset-env
+ RN_BUNDLE_ARGS: --entry-file index.js --platform android --dev false --bundle-output android/main.jsbundle --assets-dest android
+
jobs:
build:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
- - name: Install modules
- run: yarn
- - name: Run tests
- run: yarn test
+ - uses: actions/checkout@v3
+ - run: yarn
+ - run: yarn test
+ test-yarn:
+ needs: build
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ path: react-native-hcaptcha
+ - run: npx react-native init rnexample
+ - name: Run yarn add ...
+ working-directory: rnexample
+ run: |
+ yarn add file:../react-native-hcaptcha
+ yarn add --dev ${{ env.TEST_APP_DEV_DEPS }}
+ yarn add ${{ env.TEST_APP_DEPS }}
+ cp ../react-native-hcaptcha/Example.App.js App.js
+ cp ../react-native-hcaptcha/Example.jest.config.js jest.config.js
+ - run: yarn react-native bundle ${{ env.RN_BUNDLE_ARGS }}
+ working-directory: rnexample
+ - run: cat package.json
+ working-directory: rnexample
+ - run: yarn test
+ working-directory: rnexample
+ - run: npx --yes check-peer-dependencies --yarn
+ working-directory: rnexample
+ test-npm:
+ needs: build
+ runs-on: ubuntu-latest
+ steps:
+ - run: npx react-native init rnexample
+ - uses: actions/checkout@v3
+ with:
+ path: rnexample/react-native-hcaptcha
+ - name: Run npm install ...
+ working-directory: rnexample
+ run: |
+ npm i --save file:./react-native-hcaptcha
+ npm i --save --include=dev ${{ env.TEST_APP_DEV_DEPS }}
+ npm i --save ${{ env.TEST_APP_DEPS }}
+ cp ./react-native-hcaptcha/Example.App.js App.js
+ cp ./react-native-hcaptcha/Example.jest.config.js jest.config.js
+ - run: npx react-native bundle ${{ env.RN_BUNDLE_ARGS }}
+ working-directory: rnexample
+ - run: cat package.json
+ working-directory: rnexample
+ - run: npm run test --testPathPattern __tests__/App.test.js
+ working-directory: rnexample
+ - run: npx --yes check-peer-dependencies --npm
+ working-directory: rnexample
diff --git a/Example.jest.config.js b/Example.jest.config.js
new file mode 100644
index 0000000..612e0ed
--- /dev/null
+++ b/Example.jest.config.js
@@ -0,0 +1,15 @@
+module.exports = {
+ preset: 'react-native',
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
+ transformIgnorePatterns: [
+ "node_modules/(?!(react-native"
+ + "|@react-native"
+ + "|@hcaptcha"
+ + "|react-native-modal"
+ + "|react-native-webview"
+ + "|react-native-animatable"
+ + "|expo-constants"
+ + "|@unimodules"
+ + ")/)",
+ ],
+}
diff --git a/Hcaptcha.js b/Hcaptcha.js
index f3622ce..9491057 100644
--- a/Hcaptcha.js
+++ b/Hcaptcha.js
@@ -1,6 +1,10 @@
import React, { useMemo, useCallback } from 'react';
import WebView from 'react-native-webview';
import { Linking, StyleSheet, View, ActivityIndicator } from 'react-native';
+import ReactNativeVersion from 'react-native/Libraries/Core/ReactNativeVersion';
+
+import md5 from './md5';
+import hcaptchaPackage from './package.json';
const patchPostMessageJsCode = `(${String(function () {
var originalPostMessage = window.ReactNativeWebView.postMessage;
@@ -65,6 +69,23 @@ const Hcaptcha = ({
rqdata = `"${rqdata}"`;
}
+ const debugInfo = useMemo(
+ () => {
+ var result = [];
+ try {
+ const {major, minor, patch} = ReactNativeVersion.version;
+ result.push(`rnver_${major}_${minor}_${patch}`);
+ result.push('sdk_' + hcaptchaPackage.version.replaceAll('.', '_'));
+ result.push('dep_' + md5(Object.keys(global).join('')));
+ } catch (e) {
+ console.log(e);
+ } finally {
+ return result;
+ }
+ },
+ []
+ );
+
const generateTheWebViewContent = useMemo(
() =>
`
@@ -73,6 +94,9 @@ const Hcaptcha = ({
+