From 23826bd10735162e4713082d413defce5707e355 Mon Sep 17 00:00:00 2001 From: Alex Bobrikovich Date: Sat, 26 Mar 2022 19:43:45 +0100 Subject: [PATCH] Bugfix/webview version upgrade (#14) * Add debugInfo * #9 restrict minimal versios of react-native-webview and react-native-modal * Add test-npm & test-yarn CI jobs * Update md5.js * Add check-peer-dependencies stop to CI Co-authored-by: e271828- --- .github/workflows/tests.yaml | 68 ++++++++++++++-- Example.jest.config.js | 15 ++++ Hcaptcha.js | 26 ++++++- MAINTAINER.md | 2 +- __mocks__/global.js | 11 +++ __tests__/ConfirmHcaptcha.test.js | 3 - __tests__/Hcaptcha.test.js | 2 - .../ConfirmHcaptcha.test.js.snap | 3 + __tests__/__snapshots__/Hcaptcha.test.js.snap | 3 + md5.js | 77 +++++++++++++++++++ package.json | 15 ++-- 11 files changed, 206 insertions(+), 19 deletions(-) create mode 100644 Example.jest.config.js create mode 100644 __mocks__/global.js create mode 100644 md5.js 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 = ({ +