diff --git a/.circleci/config.yml b/.circleci/config.yml index fb0a5cc4..1a4c09ca 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ executors: linux_js: docker: - image: circleci/node:14.15.0 - resource_class: medium + resource_class: medium+ environment: PATH: '/opt/yarn/yarn-v1.5.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' @@ -69,7 +69,7 @@ commands: source $BASH_ENV - restore_cache: key: | - brew-cache-{{ arch }}-v1 + brew-cache-{{ arch }}-v1-3 - run: name: Install node@<> command: | @@ -91,6 +91,13 @@ commands: HOMEBREW_NO_AUTO_UPDATE=1 brew install android-commandlinetools >/dev/null touch .watchmanconfig node -v + - save_cache: + paths: + - ~/Library/Caches/Homebrew + - /usr/local/Homebrew/Library/Taps + - /usr/local/Homebrew/Library/Homebrew/vendor/ + key: | + brew-cache-{{ arch }}-v1-3 android_emulator_start: parameters: device_name: @@ -211,9 +218,6 @@ jobs: executor: macos_custom steps: - - attach_workspace: - at: . - - setup_macos_executor - ios_simulator_start @@ -227,9 +231,11 @@ jobs: - run: command: yarn e2e:build:ios:release name: build for detox + - run: command: yarn e2e:test:ios:release name: test detox + - store_artifacts: path: ./artifacts @@ -237,14 +243,13 @@ jobs: executor: name: macos_custom steps: - - attach_workspace: - at: . - setup_macos_executor - run: command: yarn install --frozen-lockfile name: yarn install - android_emulator_start + - run: command: yarn e2e:build:android:release name: build for detox diff --git a/example/.env.example b/example/.env.example index 6904a37d..2d293cbb 100644 --- a/example/.env.example +++ b/example/.env.example @@ -1,5 +1,11 @@ -API_URL_ANDROID=http://10.0.2.2:3002 -API_URL_IOS=http://localhost:3002 - # Fill in your private TEST API key below STRIPE_PRIVATE_KEY=sk_test_xxx + +# Backend API URL +API_URL=http://127.0.0.1:3002 + +# Android Backend API URL. +# The example app will default to API_URL if no specific API_URL_ANDROID is defined +# This is helpful when you're working with the android emulator as it remaps the localhost +# ip value (default is 10.0.2.2) +API_URL_ANDROID=http://10.0.2.2:3002 diff --git a/example/babel.config.js b/example/babel.config.js index adea77bd..7da12cef 100644 --- a/example/babel.config.js +++ b/example/babel.config.js @@ -4,6 +4,7 @@ const pak = require('../package.json'); module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: [ + ['module:react-native-dotenv'], [ 'module-resolver', { diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index b49b55b1..58f72c1f 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -450,11 +450,11 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: boost: a7c83b31436843459a1961bfd74b96033dc77234 - DoubleConversion: cde416483dac037923206447da6e1454df403714 + DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662 FBLazyVector: de148e8310b8b878db304ceea2fec13f2c02e3a0 FBReactNativeSpec: 6192956c9e346013d5f1809ba049af720b11c6a4 fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 - glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3 + glog: 5337263514dd6f09803962437687240c5dc39aa4 RCT-Folly: a21c126816d8025b547704b777a2ba552f3d9fa9 RCTRequired: 59d2b744d8c2bf2d9bc7032a9f654809adcf7d50 RCTTypeSafety: d0aaf7ccae5c70a4aaa3a5c3e9e0db97efae760e @@ -490,6 +490,6 @@ SPEC CHECKSUMS: StripeTerminal: da566fa62a4e7bbf0510dd27614f3087293cd79e Yoga: 32a18c0e845e185f4a2a66ec76e1fd1f958f22fa -PODFILE CHECKSUM: 4f0873ca93c8515b2736ed78b61a035f42aa658c +PODFILE CHECKSUM: 84b73709c1edcf5ac7a2639adb1bd9760a58aef7 -COCOAPODS: 1.10.1 +COCOAPODS: 1.11.2 diff --git a/example/package.json b/example/package.json index 9a677482..cbac63b8 100644 --- a/example/package.json +++ b/example/package.json @@ -8,7 +8,9 @@ "ios": "react-native run-ios", "start": "react-native start", "build:server": "babel server --out-dir dist --extensions '.ts,.tsx' --ignore '**/__tests__/**' --source-maps --copy-files --delete-dir-on-start", - "start:server": "nodemon --exec ts-node server/index.ts", + "start:server": "ts-node server/index.ts", + "start:server:ci": "ts-node server/index.ts &", + "watch:server": "nodemon --exec ts-node server/index.ts", "postinstall": "scripts/fixRN.sh" }, "dependencies": { @@ -17,11 +19,13 @@ "@react-navigation/native": "^5.x", "@react-navigation/stack": "^5.x", "@types/jest": "^27.0.2", + "@types/react-native-dotenv": "^0.2.0", "dotenv": "^10.0.0", "jest": "^27.3.1", "react": "17.0.2", "react-native": "0.66.3", "react-native-config": "^1.4.5", + "react-native-dotenv": "^3.3.1", "react-native-gesture-handler": "^1.10.3", "react-native-reanimated": "2.3.0", "react-native-safe-area-context": "^3.3.2", diff --git a/example/src/Config.ts b/example/src/Config.ts index 15344b9e..33d34fd0 100644 --- a/example/src/Config.ts +++ b/example/src/Config.ts @@ -1 +1,6 @@ -export const API_URL = 'https://stripe-backend-danwaters.herokuapp.com'; +// @ts-ignore +import { API_URL as defaultURL, API_URL_ANDROID as androidURL } from '@env'; +import { Platform } from 'react-native'; + +export const API_URL: string = + Platform.OS === 'android' && androidURL ? androidURL : defaultURL; diff --git a/example/yarn.lock b/example/yarn.lock index 264e19de..b944f8b5 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -1422,6 +1422,11 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc" integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw== +"@types/react-native-dotenv@^0.2.0": + version "0.2.0" + resolved "https://registry.npmjs.org/@types/react-native-dotenv/-/react-native-dotenv-0.2.0.tgz#32c58422a422c1adf68acce363ed791314d5a8e7" + integrity sha512-ZxX+dU/yoQc0jTk+/NWttkiuXceJyN5FpOSqDl0WynN5GDzxwH7OMruQ47qcY8llo2RD3irjvzJ9BwC8gDiq0A== + "@types/serve-static@*": version "1.13.10" resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.10.tgz#f5e0ce8797d2d7cc5ebeda48a52c96c4fa47a8d9" @@ -5755,6 +5760,13 @@ react-native-config@^1.4.5: resolved "https://registry.yarnpkg.com/react-native-config/-/react-native-config-1.4.5.tgz#6fe5895410b75e44fe4f4bf00caaf894a0981f3a" integrity sha512-5oiAsoW88SOYDg/0cleJ2vJDqv98FJUbFQYEnH4sdMtEn3AAT3lb7BkTGW8HO/t3Vk9VOruwxUUnO4tzuxzCsw== +react-native-dotenv@^3.3.1: + version "3.3.1" + resolved "https://registry.npmjs.org/react-native-dotenv/-/react-native-dotenv-3.3.1.tgz#8f399cf28ca77d860d8e7f7323e439fa60a8ca0b" + integrity sha512-gAKXout1XCwCqJ3QPGoQAF2eRzOHgOnwg3x19z+ssow8bDIksJeKBqvoHDyGziVilAIP1J0bEC9Jf+VF8nFang== + dependencies: + dotenv "^10.0.0" + react-native-gesture-handler@^1.10.3: version "1.10.3" resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-1.10.3.tgz#942bbf2963bbf49fa79593600ee9d7b5dab3cfc0" diff --git a/package.json b/package.json index 8fdb1e30..302790c7 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,8 @@ "e2e:test:ios": "detox test --configuration ios --take-screenshots failing --loglevel verbose", "e2e:build:android:release": "detox build --configuration android.emu.release", "e2e:build:ios:release": "detox build --configuration ios.sim.release", - "e2e:test:android:release": "yarn get:testbutler && detox test --configuration android.emu.release --headless --take-screenshots failing --record-logs all", - "e2e:test:ios:release": "detox test --configuration ios.sim.release --take-screenshots failing", + "e2e:test:android:release": "yarn --cwd example start:server:ci && yarn get:testbutler && detox test --configuration android.emu.release --headless --take-screenshots failing --record-logs all", + "e2e:test:ios:release": "yarn --cwd example start:server:ci && detox test --configuration ios.sim.release --take-screenshots failing", "get:testbutler": "curl -f -o ./test-butler-app.apk https://repo1.maven.org/maven2/com/linkedin/testbutler/test-butler-app/2.2.1/test-butler-app-2.2.1.apk", "docs": "npx typedoc ./src/index.tsx --out ./docs/api-reference --tsconfig ./tsconfig.json --theme minimal --theme ./docs/stripe-theme" },