Skip to content

Commit

Permalink
setup detox
Browse files Browse the repository at this point in the history
  • Loading branch information
omdxp committed Apr 9, 2023
1 parent a46b35b commit 7f92e9a
Show file tree
Hide file tree
Showing 12 changed files with 1,368 additions and 210 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ web/src/_e2e-test/screenshots

# mobile
mobile/.expo
mobile/artifacts

# data
data/nodemon.json
10 changes: 5 additions & 5 deletions mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"web": {
"favicon": "./src/assets/png/favicon.png"
},
"plugins": ["sentry-expo"],
"plugins": ["sentry-expo", "@config-plugins/detox"],
"hooks": {
"postExport": [
{
Expand All @@ -49,13 +49,13 @@
}
]
},
"runtimeVersion": {
"policy": "sdkVersion"
},
"extra": {
"eas": {
"projectId": "92897cc7-1f47-44ff-9a48-788b82c4d57b"
"projectId": "18ad1f04-aee8-49d0-b8d0-18678e9e009a"
}
},
"runtimeVersion": {
"policy": "sdkVersion"
}
}
}
57 changes: 57 additions & 0 deletions mobile/detox.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/** @type {Detox.DetoxConfig} */
module.exports = {
logger: {
level: process.env.CI ? "debug" : undefined,
},
testRunner: {
$0: "jest",
args: {
config: "src/_e2e-test/support/jest.config.js",
_: ["src/_e2e-test"],
},
},
artifacts: {
plugins: {
log: process.env.CI ? "failing" : undefined,
screenshot: "failing",
},
},
apps: {
"ios.release": {
type: "ios.app",
build:
"xcodebuild -workspace ios/eastestsexample.xcworkspace -scheme DzCodeio -configuration Release -sdk iphonesimulator -arch x86_64 -derivedDataPath ios/build",
binaryPath: "ios/build/Build/Products/Release-iphonesimulator/DzCodeio.app",
},
"android.release": {
type: "android.apk",
build:
"cd android && ./gradlew :app:assembleRelease :app:assembleAndroidTest -DtestBuildType=release && cd ..",
binaryPath: "android/app/build/outputs/apk/release/app-release.apk",
},
},
devices: {
simulator: {
type: "ios.simulator",
device: {
type: "iPhone 14",
},
},
emulator: {
type: "android.emulator",
device: {
avdName: "pixel_4",
},
},
},
configurations: {
"ios.release": {
device: "simulator",
app: "ios.release",
},
"android.release": {
device: "emulator",
app: "android.release",
},
},
};
45 changes: 45 additions & 0 deletions mobile/eas-hooks/eas-build-on-success.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

function cleanup()
{
echo 'Cleaning up...'
if [[ "$EAS_BUILD_PLATFORM" == "android" ]]; then
# Kill emulator
adb emu kill &
fi
}

if [[ "$EAS_BUILD_PROFILE" != "test" ]]; then
exit
fi

# Fail if anything errors
set -eox pipefail
# If this script exits, trap it first and clean up the emulator
trap cleanup EXIT

ANDROID_EMULATOR=pixel_4

if [[ "$EAS_BUILD_PLATFORM" == "android" ]]; then
# Start emulator
$ANDROID_SDK_ROOT/emulator/emulator @$ANDROID_EMULATOR -no-audio -no-boot-anim -no-window -use-system-libs 2>&1 >/dev/null &

# Wait for emulator
max_retry=10
counter=0
until adb shell getprop sys.boot_completed; do
sleep 10
[[ counter -eq $max_retry ]] && echo "Failed to start the emulator!" && exit 1
counter=$((counter + 1))
done

# Execute Android tests
if [[ "$EAS_BUILD_PROFILE" == "test" ]]; then
detox test --configuration android.release
fi
else
# Execute iOS tests
if [[ "$EAS_BUILD_PROFILE" == "test" ]]; then
detox test --configuration ios.release
fi
fi
40 changes: 40 additions & 0 deletions mobile/eas-hooks/eas-build-pre-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -eox pipefail

if [[ "$EAS_BUILD_RUNNER" == "eas-build" && "$EAS_BUILD_PROFILE" == "test"* ]]; then
if [[ "$EAS_BUILD_PLATFORM" == "android" ]]; then
sudo apt-get --quiet update --yes

# Install emulator & video bridge dependencies
# Source: https://github.com/react-native-community/docker-android/blob/master/Dockerfile
sudo apt-get --quiet install --yes \
libc6 \
libdbus-1-3 \
libfontconfig1 \
libgcc1 \
libpulse0 \
libtinfo5 \
libx11-6 \
libxcb1 \
libxdamage1 \
libnss3 \
libxcomposite1 \
libxcursor1 \
libxi6 \
libxext6 \
libxfixes3 \
zlib1g \
libgl1 \
pulseaudio \
socat

# Emulator must be API 31 -- API 32 and 33 fail due to https://github.com/wix/Detox/issues/3762
sdkmanager --install "system-images;android-31;google_apis;x86_64"
avdmanager --verbose create avd --force --name "pixel_4" --device "pixel_4" --package "system-images;android-31;google_apis;x86_64"
else
brew tap wix/brew
brew install applesimutils
fi
fi

10 changes: 10 additions & 0 deletions mobile/eas.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
"ios": {
"resourceClass": "m-medium"
}
},
"test": {
"android": {
"gradleCommand": ":app:assembleRelease :app:assembleAndroidTest -DtestBuildType=release",
"withoutCredentials": true
},
"ios": {
"simulator": true
},
"buildArtifactPaths": ["artifacts/**/*.png"]
}
},
"submit": {
Expand Down
12 changes: 10 additions & 2 deletions mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,30 @@
"@dzcode.io/utils": "*",
"@sentry/react-native": "4.13.0",
"debounce": "^1.2.1",
"expo": "~48.0.9",
"expo": "~48.0.10",
"expo-application": "~5.1.1",
"expo-constants": "~14.2.1",
"expo-device": "~5.2.1",
"expo-splash-screen": "~0.18.1",
"expo-status-bar": "~1.4.4",
"expo-updates": "~0.16.3",
"react": "18.2.0",
"react-native": "0.71.4",
"react-native": "0.71.6",
"react-redux": "^7.2.6",
"redux": "^4.1.2",
"redux-thunk": "^2.4.1",
"sentry-expo": "~6.1.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@config-plugins/detox": "^5.0.1",
"@dzcode.io/tooling": "*",
"@expo/ngrok": "^4.1.0",
"@types/debounce": "^1.2.0",
"@types/react": "~18.0.14",
"@types/react-test-renderer": "^18.0.0",
"babel-plugin-transform-define": "^2.0.0",
"detox": "^20.6.0",
"eas-cli": "^3.8.1",
"internal-ip": "^6.2.0",
"jest-expo": "^48.0.2",
Expand All @@ -58,6 +61,7 @@
"repository": "https://github.com/dzcode-io/dzcode.io.git"
},
"scripts": {
"android": "expo run:android",
"build": "lerna run build:alone [email protected]/mobile --include-dependencies --stream",
"build:alone:watch": "tsc --watch --preserveWatchOutput",
"build:android": "eas build -p android --no-wait --non-interactive",
Expand All @@ -82,16 +86,20 @@
"delete:screen": "rnhc delete -s",
"deploy": "eas update --channel production --message \"update\" --non-interactive",
"deploy:stg": "eas update --channel stage --message \"update\" --non-interactive",
"eas-build-on-success": "./eas-hooks/eas-build-on-success.sh",
"eas-build-post-install": "yarn build",
"eas-build-pre-install": "./eas-hooks/eas-build-pre-install.sh",
"generate:bundle-info": "ts-node ../packages/tooling/bundle-info.ts",
"generate:sentry-release": "ts-node ../packages/tooling/sentry-release.ts mobile dist",
"ios": "expo run:ios",
"lint": "yarn build && yarn lint:alone",
"lint:alone": "yarn lint:eslint . && yarn lint:prettier --check . && yarn lint:tsc",
"lint:eslint": "eslint --config ../packages/tooling/.eslintrc.json --ignore-path ../packages/tooling/.eslintignore --report-unused-disable-directives",
"lint:fix": "yarn build && yarn lint:fix:alone",
"lint:fix:alone": "yarn lint:eslint --fix . && yarn lint:prettier --write .",
"lint:prettier": "prettier --config ../packages/tooling/.prettierrc --ignore-path ../packages/tooling/.prettierignore --loglevel warn",
"lint:tsc": "tsc --noEmit",
"start": "expo start --dev-client",
"start:dev": "echo \" \n\\033[0;32mPlease run in a separate terminal session the following command:\n \n\\033[0;32myarn --cwd=mobile start:expo\n \n \"",
"start:expo": "expo start --port 1010",
"test": "yarn build && yarn test:alone",
Expand Down
12 changes: 12 additions & 0 deletions mobile/src/_e2e-test/support/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
rootDir: "../../../",
testMatch: ["<rootDir>/src/_e2e-test/tests/**/*.test.ts"],
testTimeout: 120000,
maxWorkers: 1,
globalSetup: "detox/runners/jest/globalSetup",
globalTeardown: "detox/runners/jest/globalTeardown",
reporters: ["detox/runners/jest/reporter"],
testEnvironment: "detox/runners/jest/testEnvironment",
verbose: true,
};
15 changes: 15 additions & 0 deletions mobile/src/_e2e-test/tests/contribute.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { by, device, element, expect } from "detox";

describe("Contribute screen", () => {
beforeAll(async () => {
await device.launchApp();
});

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

it('"No contributions" view should be visible', async () => {
await expect(element(by.id("no-contributions"))).toBeVisible();
});
});
2 changes: 1 addition & 1 deletion mobile/src/screens/contribute/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const ContributeScreen: FC = () => {
)}
/>
) : (
<View style={globalStyles.centerView}>
<View id="no-contributions" style={globalStyles.centerView}>
<Image
source={require("@dzcode.io/ui-mobile/assets/png/info.png")}
style={contributeStyles.emptyStateLogo}
Expand Down
1 change: 1 addition & 0 deletions packages/tooling/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ nodemon.json
*.eslintignore
*.ttf
*.ts-prunerc
*.sh
Loading

0 comments on commit 7f92e9a

Please sign in to comment.