From 623535d6011b03d1cad9c31b5249f9b8658eb3ff Mon Sep 17 00:00:00 2001 From: Birkir Gudjonsson Date: Thu, 26 Jul 2018 15:33:26 -0400 Subject: [PATCH] Fixed detox and jest tests --- __tests/SplashScreen.e2e.js | 15 - __tests/init.js | 10 - __tests/mocha.opts | 3 - e2e/SampleScreen.test.js | 11 + e2e/config.json | 3 + e2e/init.js | 19 + package.json | 68 +- scripts/{setup-jest.js => jest-setup.js} | 0 .../button/__tests__/Button.spec.tsx | 26 +- .../__snapshots__/Button.spec.tsx.snap | 53 +- src/screens/sample/Sample.tsx | 4 +- tsconfig.json | 4 +- yarn.lock | 1376 ++++++----------- 13 files changed, 625 insertions(+), 967 deletions(-) delete mode 100644 __tests/SplashScreen.e2e.js delete mode 100644 __tests/init.js delete mode 100644 __tests/mocha.opts create mode 100644 e2e/SampleScreen.test.js create mode 100644 e2e/config.json create mode 100644 e2e/init.js rename scripts/{setup-jest.js => jest-setup.js} (100%) diff --git a/__tests/SplashScreen.e2e.js b/__tests/SplashScreen.e2e.js deleted file mode 100644 index bcbc4e4..0000000 --- a/__tests/SplashScreen.e2e.js +++ /dev/null @@ -1,15 +0,0 @@ -describe('SplashScreen', () => { - - beforeEach(async () => { - await device.reloadReactNative(); - }); - - it('should have next button', async () => { - await expect(element(by.id('BUTTON_NEXT'))).toBeVisible(); - }); - - it('should show new screen after tap', async () => { - await element(by.id('BUTTON_NEXT')).tap(); - await expect(element(by.id('SPLASH_SCREEN'))).toBeVisible(); - }); -}); diff --git a/__tests/init.js b/__tests/init.js deleted file mode 100644 index 5326ee5..0000000 --- a/__tests/init.js +++ /dev/null @@ -1,10 +0,0 @@ -const detox = require('detox'); -const config = require('../package.json').detox; - -before(async () => { - await detox.init(config); -}); - -after(async () => { - await detox.cleanup(); -}); diff --git a/__tests/mocha.opts b/__tests/mocha.opts deleted file mode 100644 index 28ffbfd..0000000 --- a/__tests/mocha.opts +++ /dev/null @@ -1,3 +0,0 @@ ---recursive ---timeout 120000 ---bail diff --git a/e2e/SampleScreen.test.js b/e2e/SampleScreen.test.js new file mode 100644 index 0000000..d636ab7 --- /dev/null +++ b/e2e/SampleScreen.test.js @@ -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(); + }); + +}); diff --git a/e2e/config.json b/e2e/config.json new file mode 100644 index 0000000..1dcf55f --- /dev/null +++ b/e2e/config.json @@ -0,0 +1,3 @@ +{ + "setupTestFrameworkScriptFile" : "./init.js" +} diff --git a/e2e/init.js b/e2e/init.js new file mode 100644 index 0000000..54f016d --- /dev/null +++ b/e2e/init.js @@ -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(); +}); diff --git a/package.json b/package.json index 1af4324..8a35589 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { @@ -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", @@ -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", @@ -85,36 +84,35 @@ "typescript": "2.9.2" }, "jest": { + "preset": "react-native", + "setupFiles": [ + "/scripts/jest-setup.js" + ], "transform": { - "^.+\\.jsx?$": "/node_modules/babel-jest", "^.+\\.tsx?$": "ts-jest", + "^.+\\.jsx?$": "/node_modules/react-native/jest/preprocessor.js", "^.+\\.css$": "/scripts/jest-css.js" }, - "preset": "react-native", - "modulePaths": [ - "" - ], - "setupFiles": [ - "./scripts/setup-jest.js" - ], + "modulePaths": [ + "" + ], "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", + "testPathIgnorePatterns": [ + "/node_modules/", + "/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", @@ -122,23 +120,11 @@ "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" } } } diff --git a/scripts/setup-jest.js b/scripts/jest-setup.js similarity index 100% rename from scripts/setup-jest.js rename to scripts/jest-setup.js diff --git a/src/components/button/__tests__/Button.spec.tsx b/src/components/button/__tests__/Button.spec.tsx index 219b71d..16c599c 100644 --- a/src/components/button/__tests__/Button.spec.tsx +++ b/src/components/button/__tests__/Button.spec.tsx @@ -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(