Skip to content

Commit

Permalink
chore: Add the Detox test foundations (michalchudziak#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-oakes authored and michalchudziak committed Apr 4, 2019
1 parent c8427be commit af356af
Show file tree
Hide file tree
Showing 15 changed files with 987 additions and 603 deletions.
36 changes: 14 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1

orbs:
rn: react-native-community/react-native@dev:0.1.0-rc12
rn: react-native-community/react-native@dev:0.1.0-rc14

jobs:
checkout_code:
Expand All @@ -26,13 +26,6 @@ jobs:
- run:
name: Jest
command: yarn run test:jest
# Disabled until we have e2e tests enabled
# - run:
# name: Build Android JavaScript Bundle
# command: yarn run test:detox:android:bundle:release
# - run:
# name: Build iOS JavaScript Bundle
# command: yarn run test:detox:ios:bundle:release
# Disabled until we have semantic release enabled
# publish:
# executor: rn/linux_js
Expand Down Expand Up @@ -63,20 +56,19 @@ workflows:
build_type: release
requires:
- analyse
# Disabled until we have e2e tests enabled
# - rn/android_test:
# detox_configuration: "android.emu.release"
# requires:
# - build_android_release
# - rn/ios_build_and_test:
# project_path: "example/ios/GeolocationExample.xcodeproj"
# derived_data_path: "example/ios/build"
# device: "iPhone X"
# build_configuration: "Release"
# scheme: "GeolocationExample"
# detox_configuration: "ios.sim.release"
# requires:
# - analyse
- rn/android_test:
detox_configuration: "android.emu.release"
requires:
- build_android_release
- rn/ios_build_and_test:
project_path: "example/ios/GeolocationExample.xcodeproj"
derived_data_path: "example/ios/build"
device: "iPhone X"
build_configuration: "Release"
scheme: "GeolocationExample"
detox_configuration: "ios.sim.release"
requires:
- analyse
# Disabled until we have semantic release enabled
# - publish:
# requires:
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Currently we use `flow` for typechecking, `eslint` with `prettier` for linting a
* `yarn validate:eslint --fix`: Run `eslint` and automatically fix issues. This is useful for correcting code formatting.
* `yarn validate:flow`: Run `flow` typechecking.
* `yarn test:jest`: Run unit tests with `jest`.
* `yarn test:e2e:<ios|android>:<debug|release>`: Runs end-to-end Detox tests, for example `yarn test:e2e:ios:debug` runs the iOS E2E tests in debug mode. Before you can run it, you should build the app that can be run, by using `yarn build:e2e:<ios|android>:<debug|release>`.

## Sending a pull request
When you're sending a pull request:
Expand Down
22 changes: 21 additions & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,21 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testBuildType System.getProperty('testBuildType', 'debug')
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
if (project.hasProperty('EXAMPLE_APP_STORE_FILE')) {
storeFile file(EXAMPLE_APP_STORE_FILE)
storePassword EXAMPLE_APP_STORE_PASSWORD
keyAlias EXAMPLE_APP_KEY_ALIAS
keyPassword EXAMPLE_APP_KEY_PASSWORD
}
}
}

splits {
abi {
reset()
Expand All @@ -117,12 +131,15 @@ android {
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}

buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', "${project(':detox').projectDir}/proguard-rules-app.pro"
}
}

// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
Expand All @@ -143,6 +160,9 @@ dependencies {
implementation project(':react-native-geolocation')
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules

androidTestImplementation(project(path: ":detox"))
androidTestImplementation 'junit:junit:4.12'
}

// Run this once to be able to run the application with BUCK
Expand Down
Binary file added example/android/app/release.keystore
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.geolocationexample;

import com.wix.detox.Detox;

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
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);

@Test
public void runDetoxTests() {
Detox.runTests(mActivityRule);
}
}
8 changes: 5 additions & 3 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
minSdkVersion = 18
compileSdkVersion = 28
targetSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
kotlinVersion = '1.3.0'
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
9 changes: 8 additions & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.configureondemand=true

EXAMPLE_APP_STORE_FILE=release.keystore
EXAMPLE_APP_KEY_ALIAS=androiddebugkey
EXAMPLE_APP_STORE_PASSWORD=android
EXAMPLE_APP_KEY_PASSWORD=android
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
4 changes: 4 additions & 0 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ project(':react-native-geolocation').projectDir = new File(rootProject.projectDi
// For your application the line above will most likely be:
// project(':react-native-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/!react-native-community/geolocation/android')

// For e2e tests
include ':detox'
project(':detox').projectDir = new File(rootProject.projectDir, '../../node_modules/detox/android/detox')

include ':app'
4 changes: 4 additions & 0 deletions example/e2e/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"setupFilesAfterEnv": ["./init.js"],
"testEnvironment": "node"
}
29 changes: 29 additions & 0 deletions example/e2e/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
/* eslint-env jest, jasmine */

const detox = require('detox');
const config = require('../../package.json').detox;
const adapter = require('detox/runners/jest/adapter');

jest.setTimeout(300000);
jasmine.getEnv().addReporter(adapter);

beforeAll(async () => {
await detox.init(config, {launchApp: false});
});

beforeEach(async () => {
await adapter.beforeEach();
});

afterAll(async () => {
await adapter.afterAll();
await detox.cleanup();
});
39 changes: 39 additions & 0 deletions example/e2e/sanityTest.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
/* eslint-env jest */
/* global device, element, by */

describe('Geolocation', () => {
beforeAll(async () => {
await device.launchApp({permissions: {location: 'inuse'}});
await device.setLocation(32.0853, 34.7818);
});

beforeEach(async () => {
await device.reloadReactNative();
});

it('should load example app with no errors and show all the examples by default', async () => {
await expect(element(by.id('examplesTitle'))).toExist();
await expect(element(by.id('example-getCurrentPosition'))).toExist();
});

it('should show the test cases when the button is toggled', async () => {
await element(by.id('modeToggle')).tap();

await expect(element(by.id('testCasesTitle'))).toExist();
});

it('should show the examples again when the button is toggled twice', async () => {
await element(by.id('modeToggle')).tap();
await element(by.id('modeToggle')).tap();

await expect(element(by.id('examplesTitle'))).toExist();
});
});
2 changes: 1 addition & 1 deletion example/ios/GeolocationExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<string>Used to test the library</string>
<key>NSAppTransportSecurity</key>
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
<dict>
Expand Down
62 changes: 51 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
"test": "yarn validate:eslint && yarn validate:flow && yarn test:jest",
"validate:eslint": "eslint 'js/**/*.js' 'example/**/*.js'",
"validate:flow": "flow check",
"test:jest": "jest js/"
"test:jest": "jest js/",
"build:e2e:android:debug": "detox build -c android.emu.debug",
"build:e2e:android:release": "detox build -c android.emu.release",
"test:e2e:android:debug": "detox test -c android.emu.debug",
"test:e2e:android:release": "detox test -c android.emu.release",
"build:e2e:ios:debug": "detox build -c ios.sim.debug",
"build:e2e:ios:release": "detox build -c ios.sim.release",
"test:e2e:ios:debug": "detox test -c ios.sim.debug",
"test:e2e:ios:release": "detox test -c ios.sim.release"
},
"keywords": [
"react-native",
Expand All @@ -28,26 +36,58 @@
"react-native": "*"
},
"devDependencies": {
"@babel/core": "^7.4.0",
"@babel/runtime": "^7.4.2",
"@babel/core": "^7.4.3",
"@babel/runtime": "^7.4.3",
"@react-native-community/eslint-config": "^0.0.3",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.5.0",
"babel-jest": "^24.7.0",
"babel-plugin-module-resolver": "^3.2.0",
"eslint": "5.15.3",
"flow-bin": "^0.95.1",
"jest": "^24.5.0",
"metro-react-native-babel-preset": "^0.53.1",
"detox": "^12.1.2",
"eslint": "5.16.0",
"flow-bin": "^0.86.0",
"jest": "^24.7.0",
"metro-react-native-babel-preset": "0.51.1",
"prettier": "^1.16.4",
"react-native": "0.59.2",
"react-test-renderer": "16.8.3",
"react": "16.8.3"
"react": "16.6.3",
"react-native": "0.58.4",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native",
"setupFilesAfterEnv": [
"<rootDir>/jest.setup.js"
]
},
"detox": {
"test-runner": "jest",
"runner-config": "example/e2e/config.json",
"configurations": {
"ios.sim.debug": {
"binaryPath": "example/ios/build/Build/Products/Debug-iphonesimulator/GeolocationExample.app",
"build": "export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -project example/ios/GeolocationExample.xcodeproj -destination 'platform=iOS Simulator,name=iPhone X' -scheme GeolocationExample -parallelizeTargets -configuration Debug -derivedDataPath example/ios/build -UseModernBuildSystem=YES | xcpretty -k",
"type": "ios.simulator",
"name": "iPhone X"
},
"ios.sim.release": {
"binaryPath": "example/ios/build/Build/Products/Release-iphonesimulator/GeolocationExample.app",
"build": "export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -project example/ios/GeolocationExample.xcodeproj -destination 'platform=iOS Simulator,name=iPhone X' -scheme GeolocationExample -parallelizeTargets -configuration Release -derivedDataPath example/ios/build -UseModernBuildSystem=YES | xcpretty -k",
"type": "ios.simulator",
"name": "iPhone X"
},
"android.emu.debug": {
"binaryPath": "example/android/app/build/outputs/apk/debug/app-debug.apk",
"build": "export RCT_NO_LAUNCH_PACKAGER=true && pushd example/android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && popd",
"type": "android.emulator",
"name": "TestingAVD"
},
"android.emu.release": {
"binaryPath": "example/android/app/build/outputs/apk/release/app-release.apk",
"build": "export RCT_NO_LAUNCH_PACKAGER=true && pushd example/android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && popd",
"type": "android.emulator",
"name": "TestingAVD"
}
},
"specs": ""
}
}
Loading

0 comments on commit af356af

Please sign in to comment.