-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add detox to the project (#320)
* wip * fix debug ios * fix android * fix ios and android * add e2e_release_ios * fix lint * fix circleCI script * fix detox script * remove orb * fix config * add orb * change dir * ls * working_directory * fix config * detox clean-framework-cache && detox build-framework-cache * configure android * fix android * change avd name * uncomment jobs * write 1 test case * add typescript to detox * fix lint * moar tests * moar test * test ios * test android * android-29 * add butler * hide imageview * remove image * fix artifact path Co-authored-by: Piotr Trocki <[email protected]>
- Loading branch information
Showing
28 changed files
with
3,046 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
# Orb support is from version >= 2.1 | ||
version: 2.1 | ||
|
||
# Make sure you use the latest version of the Orb! | ||
orbs: | ||
rn: react-native-community/[email protected] | ||
|
||
# Custom jobs which are not part of the Orb | ||
jobs: | ||
checkout_code: | ||
executor: rn/linux_js | ||
executors: | ||
default: | ||
docker: | ||
- image: circleci/node:10 | ||
working_directory: ~/project | ||
|
||
commands: | ||
attach_project: | ||
steps: | ||
- checkout | ||
- persist_to_workspace: | ||
root: . | ||
paths: | ||
- . | ||
- attach_workspace: | ||
at: ~/project | ||
|
||
jobs: | ||
install-dependencies: | ||
executor: rn/linux_js | ||
executor: default | ||
steps: | ||
- attach_workspace: | ||
at: . | ||
- checkout | ||
- attach_project | ||
- restore_cache: | ||
keys: | ||
- dependencies-{{ checksum "package.json" }} | ||
|
@@ -35,49 +36,106 @@ jobs: | |
yarn install --frozen-lockfile | ||
- save_cache: | ||
key: dependencies-{{ checksum "package.json" }} | ||
paths: | ||
- node_modules | ||
paths: node_modules | ||
- save_cache: | ||
key: dependencies-example-{{ checksum "example/package.json" }} | ||
paths: | ||
- example/node_modules | ||
paths: example/node_modules | ||
- persist_to_workspace: | ||
root: . | ||
paths: | ||
- . | ||
analyse_js: | ||
executor: rn/linux_js | ||
paths: . | ||
|
||
lint: | ||
executor: default | ||
steps: | ||
- attach_project | ||
- run: | ||
name: Lint files | ||
command: | | ||
yarn lint | ||
typescript: | ||
executor: default | ||
steps: | ||
- attach_project | ||
- run: | ||
name: Typecheck files | ||
command: | | ||
yarn typescript | ||
e2e_release_ios: | ||
executor: | ||
name: rn/macos | ||
xcode_version: '11.4.0' | ||
steps: | ||
- attach_workspace: | ||
at: . | ||
- rn/yarn_install | ||
- rn/setup_macos_executor: | ||
node_version: '12.10.0' | ||
- rn/ios_simulator_start: | ||
device: 'iPhone 11' | ||
- rn/pod_install: | ||
pod_install_directory: 'example/ios' | ||
- run: | ||
command: yarn --cwd example detox:ios:build:release | ||
name: build for detox | ||
- run: | ||
name: Run ESLint | ||
command: yarn lint | ||
command: detox clean-framework-cache && detox build-framework-cache && yarn --cwd example detox:ios:test:release | ||
name: test detox | ||
- store_artifacts: | ||
path: ./example/artifacts | ||
e2e_release_android: | ||
# we need to use mac to run emulator with acceleration | ||
# see https://support.circleci.com/hc/en-us/articles/360000028928-Testing-with-Android-emulator-on-CircleCI-2-0 | ||
executor: | ||
name: rn/macos | ||
xcode_version: '11.4.0' | ||
steps: | ||
- attach_workspace: | ||
at: . | ||
- rn/setup_macos_executor: | ||
node_version: '12.10.0' | ||
- rn/android_emulator_start: | ||
logcat_grep: 'com.example.reactnativepagerview' | ||
platform_version: 'android-29' | ||
- run: | ||
name: Typescript | ||
command: yarn typescript | ||
command: yarn --cwd example detox:android:build:release | ||
name: build for detox | ||
- run: | ||
command: yarn --cwd example detox:android:test:release | ||
name: test detox | ||
- store_artifacts: | ||
path: ./example/artifacts | ||
unit-tests: | ||
executor: default | ||
steps: | ||
- attach_project | ||
- run: | ||
name: Run unit tests | ||
command: | | ||
yarn test --coverage | ||
- store_artifacts: | ||
path: coverage | ||
destination: coverage | ||
|
||
build-package: | ||
executor: default | ||
steps: | ||
- attach_project | ||
- run: | ||
name: Build package | ||
command: | | ||
yarn prepare | ||
workflows: | ||
test: | ||
build-and-test: | ||
jobs: | ||
# Checkout the code and persist to the Workspace | ||
# Note: This is a job which is defined above and not part of the Orb | ||
- checkout_code | ||
- install-dependencies: | ||
- install-dependencies | ||
- lint: | ||
requires: | ||
- checkout_code | ||
|
||
# Analyze the Javascript using ESLint, Flow, and Jest | ||
# Note: This is a job which is defined above and not part of the Orb | ||
- analyse_js: | ||
- install-dependencies | ||
- typescript: | ||
requires: | ||
- install-dependencies | ||
|
||
# Build the Android app in debug mode | ||
- rn/android_build: | ||
name: build_android | ||
project_path: "example/android" | ||
build_type: debug | ||
- e2e_release_ios: | ||
requires: | ||
- install-dependencies | ||
- e2e_release_android: | ||
requires: | ||
- analyse_js | ||
- install-dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
module.exports = { | ||
root: true, | ||
extends: '@react-native-community', | ||
globals: { | ||
expect: true, | ||
element: true, | ||
by: true, | ||
device: true, | ||
beforeAll: true, | ||
beforeEach: true, | ||
describe: true, | ||
it: true, | ||
afterAll: true, | ||
jest: true, | ||
jasmine: true, | ||
waitFor: true, | ||
detoxCircus: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,4 @@ buck-out/ | |
|
||
example/ios/Pods/ | ||
!debug.keystore | ||
test-butler-app.apk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"testRunner": "jest", | ||
"runnerConfig": "e2e/config.json", | ||
"apps": { | ||
"ios.debug": { | ||
"type": "ios.app", | ||
"binaryPath": "./ios/build/Build/Products/Debug-iphonesimulator/PagerViewExample.app", | ||
"build": "xcodebuild -workspace ios/PagerViewExample.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 11' -scheme PagerViewExample -configuration Debug -derivedDataPath ios/build -UseModernBuildSystem=YES" | ||
}, | ||
"ios.release": { | ||
"type": "ios.app", | ||
"binaryPath": "ios/build/Build/Products/Release-iphonesimulator/PagerViewExample.app", | ||
"build": "export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -workspace ios/PagerViewExample.xcworkspace -configuration release -scheme PagerViewExample -sdk iphonesimulator -derivedDataPath ios/build" | ||
}, | ||
"android.debug": { | ||
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk", | ||
"testBinaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk", | ||
"build": "export RCT_NO_LAUNCH_PACKAGER=true && (cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug)", | ||
"type": "android.apk" | ||
}, | ||
"android.release": { | ||
"binaryPath": "android/app/build/outputs/apk/release/app-release.apk", | ||
"build": "export RCT_NO_LAUNCH_PACKAGER=true && (cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release)", | ||
"type": "android.apk" | ||
} | ||
}, | ||
"devices": { | ||
"simulator": { | ||
"type": "ios.simulator", | ||
"device": { | ||
"type": "iPhone 11" | ||
} | ||
}, | ||
"emulator": { | ||
"type": "android.emulator", | ||
"utilBinaryPaths": ["./test-butler-app.apk"], | ||
"device": { | ||
"avdName": "TestingAVD" | ||
} | ||
} | ||
}, | ||
"configurations": { | ||
"ios.sim.debug": { | ||
"device": "simulator", | ||
"app": "ios.debug" | ||
}, | ||
"ios.sim.release": { | ||
"device": "simulator", | ||
"app": "ios.release" | ||
}, | ||
"android.emu.debug": { | ||
"device": "emulator", | ||
"app": "android.debug" | ||
}, | ||
"android.emu.release": { | ||
"device": "emulator", | ||
"app": "android.release" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
example/android/app/src/androidTest/java/com/example/reactnativepagerview/DetoxTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.example.reactnativepagerview; | ||
|
||
import com.wix.detox.Detox; | ||
import com.wix.detox.config.DetoxConfig; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.filters.LargeTest; | ||
import androidx.test.rule.ActivityTestRule; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public class DetoxTest { | ||
@Rule | ||
// Replace 'MainActivity' with the value of android:name entry in | ||
// <activity> in AndroidManifest.xml | ||
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false); | ||
|
||
@Test | ||
public void runDetoxTests() { | ||
DetoxConfig detoxConfig = new DetoxConfig(); | ||
detoxConfig.idlePolicyConfig.masterTimeoutSec = 90; | ||
detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60; | ||
detoxConfig.rnContextLoadTimeoutSec = (BuildConfig.DEBUG ? 180 : 60); | ||
|
||
Detox.runTests(mActivityRule, detoxConfig); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...id/app/src/androidTest/java/com/example/reactnativepagerview/DetoxTestAppJUnitRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.reactnativepagerview; | ||
|
||
import android.os.Bundle; | ||
|
||
import com.linkedin.android.testbutler.TestButler; | ||
|
||
import androidx.test.runner.AndroidJUnitRunner; | ||
|
||
public class DetoxTestAppJUnitRunner extends AndroidJUnitRunner { | ||
@Override | ||
public void onStart() { | ||
TestButler.setup(getTargetContext()); | ||
super.onStart(); | ||
} | ||
|
||
@Override | ||
public void finish(int resultCode, Bundle results) { | ||
TestButler.teardown(getTargetContext()); | ||
super.finish(resultCode, results); | ||
} | ||
} |
Oops, something went wrong.