Skip to content

Commit 5356677

Browse files
committed
Setup Detox
1 parent eb8c7f3 commit 5356677

File tree

16 files changed

+424
-50
lines changed

16 files changed

+424
-50
lines changed

__e2e__/TestApp/.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"globals": {
3+
"__DEV__": true
4+
}
5+
}

__e2e__/TestApp/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ buck-out/
5454

5555
# Bundle artifact
5656
*.jsbundle
57+
58+
# Detox artifacts
59+
artifacts/

__e2e__/TestApp/App.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,14 @@
77
* @lint-ignore-every XPLATJSCOPYRIGHT1
88
*/
99

10-
import React, {Component} from 'react';
11-
import {Platform, StyleSheet, Text, View} from 'react-native';
10+
import React, { Component } from 'react';
11+
import { Platform, StyleSheet, Text, View } from 'react-native';
1212

1313
const instructions = Platform.select({
14-
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
15-
android:
16-
'Double tap R on your keyboard to reload,\n' +
17-
'Shake or press menu button for dev menu',
14+
ios: 'Press Cmd+R to reload,\nCmd+D or shake for dev menu',
15+
android: 'Double tap R on your keyboard to reload,\nShake or press menu button for dev menu',
1816
});
1917

20-
type Props = {};
21-
export default class App extends Component<Props> {
22-
render() {
23-
return (
24-
<View style={styles.container}>
25-
<Text style={styles.welcome}>Welcome to React Native!</Text>
26-
<Text style={styles.instructions}>To get started, edit App.js</Text>
27-
<Text style={styles.instructions}>{instructions}</Text>
28-
</View>
29-
);
30-
}
31-
}
32-
3318
const styles = StyleSheet.create({
3419
container: {
3520
flex: 1,
@@ -48,3 +33,16 @@ const styles = StyleSheet.create({
4833
marginBottom: 5,
4934
},
5035
});
36+
37+
type Props = {};
38+
export default class App extends Component<Props> {
39+
render() {
40+
return (
41+
<View testID="home" style={styles.container}>
42+
<Text style={styles.welcome}>Welcome to React Native!</Text>
43+
<Text style={styles.instructions}>To get started, edit App.js</Text>
44+
<Text style={styles.instructions}>{instructions}</Text>
45+
</View>
46+
);
47+
}
48+
}

__e2e__/TestApp/__e2e__/.eslintrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"globals": {
3+
"device": true,
4+
"element": true,
5+
"waitFor": true,
6+
"by": true,
7+
"simctl": true
8+
}
9+
}

__e2e__/TestApp/__e2e__/app.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const delay = time => new Promise(resolve => setTimeout(resolve, time));
2+
3+
describe('Main', () => {
4+
beforeEach(async () => {
5+
await device.reloadReactNative();
6+
await delay(500);
7+
});
8+
it('should open the article', async () => {
9+
await expect(element(by.id('home'))).toBeVisible();
10+
});
11+
});

__e2e__/TestApp/__e2e__/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"setupTestFrameworkScriptFile": "./setup.js",
3+
"testEnvironment": "node"
4+
}

__e2e__/TestApp/__e2e__/setup.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* global jasmine device */
2+
3+
import childProcess from 'child_process';
4+
import { promisify } from 'util';
5+
6+
/* eslint-disable import/no-unresolved */
7+
const detox = require('detox');
8+
const adapter = require('detox/runners/jest/adapter');
9+
const { detox: config } = require('../package.json');
10+
11+
const exec = promisify(childProcess.exec);
12+
13+
global.simctl = {
14+
pbcopy: (content, device = 'booted') => exec(`echo '${content}' | xcrun simctl pbcopy ${device}`),
15+
};
16+
17+
jest.setTimeout(120000);
18+
jasmine.getEnv().addReporter(adapter);
19+
20+
beforeAll(async () => {
21+
await detox.init(config);
22+
});
23+
24+
beforeEach(async () => {
25+
await adapter.beforeEach();
26+
});
27+
28+
afterAll(async () => {
29+
await adapter.afterAll();
30+
await detox.cleanup();
31+
});

__e2e__/TestApp/__tests__/App.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

__e2e__/TestApp/android/app/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ android {
103103
targetSdkVersion rootProject.ext.targetSdkVersion
104104
versionCode 1
105105
versionName "1.0"
106+
107+
testBuildType System.getProperty('testBuildType', 'debug') //this will later be used to control the test apk build type
108+
missingDimensionStrategy "minReactNative", "minReactNative46" //read note
109+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
106110
}
107111
splits {
108112
abi {
@@ -138,6 +142,11 @@ dependencies {
138142
implementation fileTree(dir: "libs", include: ["*.jar"])
139143
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
140144
implementation "com.facebook.react:react-native:+" // From node_modules
145+
146+
androidTestImplementation(project(path: ":detox"))
147+
androidTestImplementation 'junit:junit:4.12'
148+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
149+
androidTestImplementation 'com.android.support.test:rules:1.0.1'
141150
}
142151

143152
// Run this once to be able to run the application with BUCK
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.testapp;
2+
3+
import android.support.test.filters.LargeTest;
4+
import android.support.test.rule.ActivityTestRule;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import com.wix.detox.Detox;
8+
9+
import org.junit.Rule;
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
13+
@RunWith(AndroidJUnit4.class)
14+
@LargeTest
15+
public class DetoxTest {
16+
17+
@Rule
18+
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
19+
20+
@Test
21+
public void runDetoxTests() throws InterruptedException {
22+
Detox.runTests(mActivityRule);
23+
}
24+
}

0 commit comments

Comments
 (0)