Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Fixed detox and jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
birkir committed Jul 26, 2018
1 parent 3527e79 commit 623535d
Show file tree
Hide file tree
Showing 13 changed files with 625 additions and 967 deletions.
15 changes: 0 additions & 15 deletions __tests/SplashScreen.e2e.js

This file was deleted.

10 changes: 0 additions & 10 deletions __tests/init.js

This file was deleted.

3 changes: 0 additions & 3 deletions __tests/mocha.opts

This file was deleted.

11 changes: 11 additions & 0 deletions e2e/SampleScreen.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
describe('SplashScreen', () => {

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

it('should show sample screen', async () => {
await expect(element(by.id('SAMPLE_SCREEN'))).toBeVisible();
});

});
3 changes: 3 additions & 0 deletions e2e/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"setupTestFrameworkScriptFile" : "./init.js"
}
19 changes: 19 additions & 0 deletions e2e/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const detox = require('detox');
const config = require('../package.json').detox;
const adapter = require('detox/runners/jest/adapter');

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

beforeAll(async () => {
await detox.init(config);
});

beforeEach(async function() {
await adapter.beforeEach();
});

afterAll(async () => {
await adapter.afterAll();
await detox.cleanup();
});
68 changes: 27 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
"private": true,
"scripts": {
"build:env": "sh ./scripts/build-env.sh",
"build:e2e": "detox build --configuration $E2E_CONFIG",
"build:e2e:ios": "E2E_CONFIG=ios.sim.release yarn build:e2e",
"build:e2e:android": "E2E_CONFIG=android.emu.release yarn build:e2e",
"build:e2e:ios": "detox build --configuration ios.sim.release",
"build:e2e:android": "detox build --configuration android.emu.release",
"start": "node node_modules/react-native/local-cli/cli.js start",
"rename": "./scripts/rename.sh",
"test": "jest",
"test:e2e": "detox test --configuration $E2E_CONFIG",
"test:e2e:ios": "E2E_CONFIG=ios.sim.release yarn test:e2e",
"test:e2e:android": "E2E_CONFIG=android.emu.release yarn test:e2e",
"test:e2e": "yarn build:e2e:ios && yarn test:e2e:ios",
"test:e2e:ios": "detox test --configuration ios.sim.release",
"test:e2e:android": "detox test --configuration android.emu.release",
"lint": "yarn tslint",
"tslint": "tslint src/**/*.ts src/**/*.tsx",
"precommit": "lint-staged",
Expand All @@ -30,15 +29,15 @@
"lodash": "4.17.10",
"mobx": "5.0.3",
"mobx-react": "5.2.3",
"mobx-state-tree": "3.0.0",
"mobx-state-tree": "3.0.2",
"react": "16.4.1",
"react-native": "0.56.0",
"react-native-code-push": "5.4.0",
"react-native-config": "0.11.5",
"react-native-fast-image": "4.0.14",
"react-native-firebase": "4.3.7",
"react-native-firebase": "4.3.8",
"react-native-navigation": "2.0.2394",
"react-native-sentry": "0.38.2",
"react-native-sentry": "0.38.3",
"react-native-version-number": "0.3.4"
},
"devDependencies": {
Expand All @@ -56,7 +55,7 @@
"@types/react": "16.4.6",
"@types/react-native": "0.56.3",
"@types/react-native-navigation": "1.1.12",
"@types/react-test-renderer": "^16.0.1",
"@types/react-test-renderer": "16.0.1",
"babel-core": "^7.0.0-0",
"babel-jest": "23.4.0",
"babel-plugin-module-resolver": "3.1.1",
Expand All @@ -74,7 +73,7 @@
"react-dom": "16.4.1",
"react-native-css-transformer": "1.2.2",
"react-native-typescript-transformer": "1.2.10",
"react-native-ueno-css-modules": "1.0.5",
"react-native-ueno-css-modules": "1.0.8",
"react-test-renderer": "16.4.1",
"stylus": "0.54.5",
"ts-jest": "23.0.1",
Expand All @@ -85,60 +84,47 @@
"typescript": "2.9.2"
},
"jest": {
"preset": "react-native",
"setupFiles": [
"<rootDir>/scripts/jest-setup.js"
],
"transform": {
"^.+\\.jsx?$": "<rootDir>/node_modules/babel-jest",
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "<rootDir>/node_modules/react-native/jest/preprocessor.js",
"^.+\\.css$": "<rootDir>/scripts/jest-css.js"
},
"preset": "react-native",
"modulePaths": [
"<rootDir>"
],
"setupFiles": [
"./scripts/setup-jest.js"
],
"modulePaths": [
"<rootDir>"
],
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testPathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/e2e/"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"globals": {
"ts-jest": {
"useBabelrc": true
}
}
"json",
"node"
]
},
"detox": {
"test-runner": "mocha",
"specs": "__tests__",
"runner-config": "__tests__/mocha.opts",
"test-runner": "jest",
"specs": "e2e",
"configurations": {
"ios.sim.release": {
"binaryPath": "ios/build/Build/Products/Release-iphonesimulator/react-native-starter.app",
"build": "export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -workspace ios/react-native-starter.xcworkspace -scheme react-native-starter -configuration Release -sdk iphonesimulator -derivedDataPath ios/build -quiet",
"type": "ios.simulator",
"name": "iPhone 7 Plus"
},
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/react-native-starter.app",
"build": "xcodebuild -workspace ios/react-native-starter.xcworkspace -scheme react-native-starter -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build -quiet",
"type": "ios.simulator",
"name": "iPhone 7 Plus"
},
"android.emu.release": {
"binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
"build": "pushd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && popd",
"type": "android.emulator",
"name": "Nexus_5_API_27"
},
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build": "pushd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && popd",
"type": "android.emulator",
"name": "Nexus_5_API_27"
}
}
}
Expand Down
File renamed without changes.
26 changes: 15 additions & 11 deletions src/components/button/__tests__/Button.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import 'react-native';
import * as React from 'react';
import * as testRenderer from 'react-test-renderer';
// import { shallow } from 'enzyme';

const Button = () => null;
import { shallow } from 'enzyme';
import Button from '../Button';

test('renders correctly', () => {
const tree = testRenderer.create(<Button />).toJSON();

const tree = testRenderer.create(<Button title="test" />).toJSON();
expect(tree).toMatchSnapshot();
});

// test('Button renders children text', () => {
// const text = 'Sample text';
// const button = shallow(<Button />);
// expect(button.findWhere(c => c.text() === text)).toBeTruthy();
// });
test('Button renders children text', () => {
const text = 'Sample text';
const button = shallow(<Button title={text} />);
expect(button.findWhere(c => c.text() === text)).toHaveLength(1);
});

test('Button calls onPress function', () => {
const onPress = jest.fn();
const button = shallow(<Button title="demo" onPress={onPress} />);
button.simulate('press');
expect(onPress).toHaveBeenCalled();
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `null`;
exports[`renders correctly 1`] = `
<View
accessibilityComponentType="button"
accessibilityTraits={
Array [
"button",
]
}
accessible={true}
isTVSelectable={true}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"opacity": 1,
}
}
>
<View
style={
Array [
Object {
"backgroundColor": "#f8f8f8",
"borderRadius": 4,
},
]
}
>
<Text
style={
Array [
Object {
"color": "black",
"fontSize": 18,
"paddingBottom": 12,
"paddingLeft": 12,
"paddingRight": 12,
"paddingTop": 12,
"textAlign": "center",
},
]
}
>
test
</Text>
</View>
</View>
`;
4 changes: 2 additions & 2 deletions src/screens/sample/Sample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export default class Sample extends React.Component<Props> {

render() {
return (
<View style={styles.host} testID={this.props.testID}>
<View style={styles.host} testID="SAMPLE_SCREEN">
<Text style={styles.text}>Counter: {UI.counter}</Text>
<Button title="Sample" onPress={UI.increment} />
<Button title="Increment" onPress={UI.increment} testID="BUTTON_INCREMENT" />
</View>
);
}
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "es2015",
"module": "es2015",
"jsx": "react-native",
"module": "commonjs",
"jsx": "react",
"noEmit": true,
"moduleResolution": "node",
"strictPropertyInitialization": false,
Expand Down
Loading

0 comments on commit 623535d

Please sign in to comment.