Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: init detox and eas config for e2e tests #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .detoxrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
module.exports = {
logger: {
level: process.env.CI ? 'debug' : undefined,
},
testRunner: {
args: {
$0: 'jest',
config: 'e2e.jest.config.ts',
},
jest: {
setupTimeout: 120000,
},
},
artifacts: {
plugins: {
log: process.env.CI ? 'failing' : undefined,
screenshot: 'failing',
},
},
apps: {
ios: {
type: 'ios.app',
binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/Templateqa.app',
build:
'xcodebuild -workspace ios/Templateqa.xcworkspace -scheme Templateqa -configuration Release -sdk iphonesimulator -arch x86_64 -derivedDataPath ios/build',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD: needs to replace -scheme with a generic based on bootstrap script

},
android: {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
testBinaryPath:
'android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk',
build:
'cd android && ./gradlew app:assembleRelease app:assembleAndroidTest -DtestBuildType=release && cd ..',
},
},
devices: {
simulator: {
type: 'ios.simulator',
device: {
type: 'iPhone 14',
},
},
attached: {
type: 'android.attached',
device: {
adbName: '.*',
},
},
emulator: {
type: 'android.emulator',
device: {
avdName: 'pixel_4',
},
},
},
configurations: {
ios: {
device: 'simulator',
app: 'ios',
},
'android.att': {
device: 'attached',
app: 'android',
},
'android.emu': {
device: 'emulator',
app: 'android',
},
},
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ dist/
# .env.staging
# Local Netlify folder
.netlify

artifacts/
3 changes: 2 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"fallbackToCacheTimeout": 0
},
"userInterfaceStyle": "automatic",
"version": "1.0.0"
"version": "1.0.0",
"plugins": ["@config-plugins/detox"]
}
}
16 changes: 16 additions & 0 deletions e2e.jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Config } from 'jest'

const config: Config = {
rootDir: '.',
testMatch: ['<rootDir>/e2e/**/*.test.ts'],
testTimeout: 120000,
maxWorkers: 1,
preset: 'ts-jest',
globalSetup: 'detox/runners/jest/globalSetup',
globalTeardown: 'detox/runners/jest/globalTeardown',
reporters: ['detox/runners/jest/reporter'],
testEnvironment: 'detox/runners/jest/testEnvironment',
verbose: true,
}

export default config
43 changes: 43 additions & 0 deletions e2e/auth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { by, device, element, expect } from 'detox'

const validEmail = 'test@example.com'
const validPassword = '123456'

describe('Auth', () => {
beforeAll(async () => {
const isAndroid = (await device.getPlatform()) === 'android'
if (!isAndroid) {
await device.clearKeychain()
}
await device.launchApp({ delete: isAndroid, newInstance: true })
})

it('should sign in successfully', async () => {
const isAndroid = (await device.getPlatform()) === 'android'

const emailInput = element(by.id('emailInput'))
const passwordInput = element(by.id('passwordInput'))
const signInButton = element(by.id('signInButton'))

if (isAndroid) {
await waitFor(emailInput).toBeVisible().withTimeout(5000)
await waitFor(passwordInput).toBeVisible().withTimeout(5000)
}

await emailInput.replaceText(validEmail)

await passwordInput.replaceText(validPassword)

if (isAndroid) {
await waitFor(signInButton).toBeVisible().withTimeout(5000)
}
await signInButton.tap()

const homeScreen = element(by.id('homeScreen'))
if (isAndroid) {
await waitFor(homeScreen).toBeVisible().withTimeout(5000)
}

await expect(homeScreen).toBeVisible()
})
})
10 changes: 10 additions & 0 deletions eas.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
"channel": "qa",
"distribution": "store",
"ios": { "autoIncrement": "buildNumber" }
},
"e2e": {
"android": {
"gradleCommand": ":app:assembleRelease :app:assembleAndroidTest -DtestBuildType=release",
"withoutCredentials": true
},
"ios": {
"simulator": true
},
"buildArtifactPaths": ["artifacts/**/*.png"]
}
},
"cli": {
Expand Down
36 changes: 0 additions & 36 deletions gitignore

This file was deleted.

12 changes: 0 additions & 12 deletions jest.config.json

This file was deleted.

17 changes: 17 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Config } from 'jest'

const config: Config = {
preset: 'jest-expo',
setupFiles: ['./jest.setup.js'],
testPathIgnorePatterns: ['<rootDir>/e2e/', '<rootDir>/node_modules/'],
transformIgnorePatterns: [
'node_modules/(?!(jest-)?react-native|@react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg|@sentry/.*)',
],
rootDir: './',
moduleNameMapper: {
'~(.*)': '<rootDir>/src/$1',
},
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
}

export default config
46 changes: 29 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,67 +22,76 @@
"author": "BinarApps",
"license": "MIT",
"scripts": {
"android": "cross-env cross-env IS_DEV=1 expo start --android",
"android": "expo run:android",
"bootstrap:new_app": "yarn && node ./scripts/bootstrap.js",
"build:production": "yarn prepare:production && eas build --platform all --profile production",
"build:production:android": "yarn prepare:production && eas build --platform android --profile production",
"build:production:ios": "yarn prepare:production && eas build --platform ios --profile production",
"build:production": "yarn prepare:production && eas build --platform all --profile production",
"build:qa": "yarn prepare:qa && eas build --platform all --profile qa",
"build:qa:android": "yarn prepare:qa && eas build --platform android --profile qa",
"build:qa:ios": "yarn prepare:qa && eas build --platform ios --profile qa",
"build:qa": "yarn prepare:qa && eas build --platform all --profile qa",
"build:staging": "yarn prepare:staging && eas build --platform all --profile staging",
"build:staging:android": "yarn prepare:staging && eas build --platform android --profile staging",
"build:staging:ios": "yarn prepare:staging && eas build --platform ios --profile staging",
"build:staging": "yarn prepare:staging && eas build --platform all --profile staging",
"deploy:production": "yarn prepare:production && eas build --platform all --profile production --auto-submit --non-interactive",
"deploy:production:android": "yarn prepare:production && eas build --platform android --profile production --auto-submit --non-interactive",
"deploy:production:ios": "yarn prepare:production && eas build --platform ios --profile production --auto-submit --non-interactive",
"deploy:production": "yarn prepare:production && eas build --platform all --profile production --auto-submit --non-interactive",
"deploy:qa": "yarn prepare:qa && eas build --platform all --profile qa --auto-submit --non-interactive",
"deploy:qa:android": "yarn prepare:qa && eas build --platform android --profile qa --auto-submit --non-interactive",
"deploy:qa:ios": "yarn prepare:qa && eas build --platform ios --profile qa --auto-submit --non-interactive",
"deploy:qa": "yarn prepare:qa && eas build --platform all --profile qa --auto-submit --non-interactive",
"deploy:staging": "yarn prepare:staging && eas build --platform all --profile staging --auto-submit --non-interactive",
"deploy:staging:android": "yarn prepare:staging && eas build --platform android --profile staging --auto-submit --non-interactive",
"deploy:staging:ios": "yarn prepare:staging && eas build --platform ios --profile staging --auto-submit --non-interactive",
"deploy:staging": "yarn prepare:staging && eas build --platform all --profile staging --auto-submit --non-interactive",
"eas:build:on:success": "scripts/eas-hooks/eas-build-on-success.sh",
"eas:build:pre:install": "scripts/eas-hooks/eas-build-pre-install.sh",
"eject": "expo eject",
"generate:component": "node ./scripts/create_new_component.js && yarn eslint src --fix && yarn tsc",
"generate:env:production": "scripts/generate_dotenv.sh production",
"generate:env:qa": "scripts/generate_dotenv.sh qa",
"generate:env:staging": "scripts/generate_dotenv.sh staging",
"generate:icon:types": "node ./scripts/generate_icon_types.js",
"generate:screen": "node ./scripts/create_new_screen.js && yarn eslint src --fix && yarn tsc",
"ios": "cross-env IS_DEV=1 expo start --ios",
"ios": "expo run:ios",
"lint": "eslint src && yarn tsc",
"login": "expo login",
"logout": "expo logout",
"postinstall": "patch-package",
"prepare": "husky install",
"prepare:production": "yarn generate:env:production && BASH_ENV=./.env scripts/upload_env.sh",
"prepare:qa": "yarn generate:env:qa && BASH_ENV=./.env scripts/upload_env.sh",
"prepare:staging": "yarn generate:env:staging && BASH_ENV=./.env scripts/upload_env.sh",
"prepare": "husky install",
"prepare:test:e2e:android:att": "npx expo prebuild -p android && detox build --configuration android.att",
"prepare:test:e2e:android:emu": "npx expo prebuild -p android && detox build --configuration android.emu",
"prepare:test:e2e:ios": "npx expo prebuild -p ios && detox build --configuration ios",
"prettier:write": "prettier --write ./src",
"register": "expo register",
"start": "cross-env IS_DEV=1 expo start -c -g",
"start:fast": "EXPO_USE_EXOTIC=1 expo start --clear",
"start": "cross-env IS_DEV=1 expo start -c",
"test": "jest --watch --coverage=false --changedSince=origin/main",
"test:debug": "jest -o --watch --coverage=false",
"test:e2e:android:att": "yarn prepare:test:e2e:android:att && detox test --configuration android.att",
"test:e2e:android:emu": "yarn prepare:test:e2e:android:emu && detox test --configuration android.emu",
"test:e2e:ios": "yarn prepare:test:e2e:ios && detox test --configuration ios",
"test:final": "jest",
"test": "jest --watch --coverage=false --changedSince=origin/main",
"typecheck": "eslint .eslintrc.js --fix",
"update:expo_go": "yarn prepare:qa && cross-env IS_DEV=1 eas update --auto",
"update:production": "yarn prepare:production && eas update --branch production --message=\"ENV: Production\"",
"update:production:android": "yarn prepare:production && eas update --branch production --platform android",
"update:production:ios": "yarn prepare:production && eas update --branch production --platform ios",
"update:production": "yarn prepare:production && eas update --branch production --message=\"ENV: Production\"",
"update:qa": "yarn prepare:qa && eas update --branch qa --message=\"ENV: QA\"",
"update:qa:android": "yarn prepare:qa && eas update --branch qa --platform android",
"update:qa:ios": "yarn prepare:qa && eas update --branch qa --platform ios",
"update:qa": "yarn prepare:qa && eas update --branch qa --message=\"ENV: QA\"",
"update:staging": "yarn prepare:staging && eas update --branch staging --message=\"ENV: Staging\"",
"update:staging:android": "yarn prepare:staging && eas update --branch staging --platform android",
"update:staging:ios": "yarn prepare:staging && eas update --branch staging --platform ios",
"update:staging": "yarn prepare:staging && eas update --branch staging --message=\"ENV: Staging\"",
"updateSnapshots": "jest -u --coverage=false",
"upload": "yarn upload:ios && yarn upload:android",
"web:build": "expo export:web",
"web": "cross-env IS_DEV=1 expo start --web",
"web:build": "expo export:web",
"whoami": "expo whoami"
},
"dependencies": {
"@config-plugins/detox": "^6.0.0",
"@expo/vector-icons": "^13.0.0",
"@gorhom/bottom-sheet": "^4.4.7",
"@motify/interactions": "^0.17.1",
Expand Down Expand Up @@ -119,14 +128,14 @@
"expo-updates": "~0.18.9",
"expo-web-browser": "~12.3.2",
"i18next": "^23.2.10",
"jest": "^29.6.1",
"jest": "^29.6.4",
"moti": "^0.25.3",
"native-base": "^3.4.28",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.45.1",
"react-i18next": "^13.0.2",
"react-native": "0.72.1",
"react-native": "0.72.4",
"react-native-gesture-handler": "~2.9.0",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-notificated": "^0.1.0",
Expand Down Expand Up @@ -161,6 +170,7 @@
"babel-plugin-module-resolver": "^5.0.0",
"babel-preset-expo": "^9.5.0",
"cross-env": "^7.0.3",
"detox": "^20.11.4",
"dotenv": "^16.3.1",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
Expand All @@ -181,6 +191,8 @@
"react-test-renderer": "^18.2.0",
"readline": "^1.3.0",
"select-prompt": "^0.3.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.3",
"xmlhttprequest": "^1.8.0"
},
Expand Down
Loading
Loading