Skip to content

Commit

Permalink
chore: add detox to the project (#320)
Browse files Browse the repository at this point in the history
* 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
troZee and Piotr Trocki authored Apr 12, 2021
1 parent 4295932 commit a4f3ed4
Show file tree
Hide file tree
Showing 28 changed files with 3,046 additions and 394 deletions.
146 changes: 102 additions & 44 deletions .circleci/config.yml
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" }}
Expand All @@ -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
15 changes: 15 additions & 0 deletions .eslintrc.js
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,
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ buck-out/

example/ios/Pods/
!debug.keystore
test-butler-app.apk
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ PagerView_kotlinVersion=1.3.50
PagerView_compileSdkVersion=29
PagerView_buildToolsVersion=29.0.2
PagerView_targetSdkVersion=29
PagerView_minSdkVersion=17
PagerView_minSdkVersion=18
60 changes: 60 additions & 0 deletions example/.detoxrc.json
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"
}
}
}
11 changes: 9 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import com.android.build.OutputFile

project.ext.react = [
enableHermes: false, // clean and rebuild if changing
entryFile: "index.tsx",
entryFile: "index.js",
]

apply from: "../../node_modules/react-native/react.gradle"
Expand Down Expand Up @@ -133,6 +133,9 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testBuildType System.getProperty('testBuildType', 'debug') // This will later be used to control the test apk build type
// testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
testInstrumentationRunner 'com.example.reactnativepagerview.DetoxTestAppJUnitRunner'
}
splits {
abi {
Expand All @@ -159,7 +162,8 @@ android {
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
// proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
}
}
// applicationVariants are e.g. debug, release
Expand Down Expand Up @@ -205,6 +209,9 @@ dependencies {
}

implementation project(':reactnativepagerview')
androidTestImplementation('com.wix:detox:+')
androidTestImplementation 'com.linkedin.testbutler:test-butler-library:2.2.1'
androidTestUtil 'com.linkedin.testbutler:test-butler-app:2.2.1'
}

task downloadDependencies() {
Expand Down
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);
}
}
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);
}
}
Loading

0 comments on commit a4f3ed4

Please sign in to comment.