Skip to content

Commit a6c2819

Browse files
committed
chore: Run E2E tests in CI
1 parent e24a57a commit a6c2819

File tree

15 files changed

+488
-342
lines changed

15 files changed

+488
-342
lines changed

.detoxrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = {
4545
simulator: {
4646
type: 'ios.simulator',
4747
device: {
48-
type: 'iPhone 15 Pro',
48+
type: 'iPhone SE (3rd generation)',
4949
},
5050
},
5151
attached: {

.env.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
BASE_API_URL=
22
AUTH_STORAGE_KEY=abc123
3-
DEFAULT_LOCALE=en
3+
DEFAULT_LOCALE=en
4+
MOCK_API=

.env.e2e

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BASE_API_URL="http://test-api-with-msw.rn"
2+
AUTH_STORAGE_KEY=abc123
3+
DEFAULT_LOCALE=en
4+
MOCK_API=true

.github/workflows/e2e_android.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: E2E Android
2+
on:
3+
push:
4+
branches:
5+
- master
6+
workflow_call:
7+
8+
jobs:
9+
e2e-android:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
cache: yarn
20+
node-version-file: .node-version
21+
22+
- name: Delete unnecessary tools
23+
uses: jlumbroso/[email protected]
24+
with:
25+
android: false
26+
tool-cache: true
27+
dotnet: true
28+
haskell: true
29+
swap-storage: true
30+
docker-images: false
31+
large-packages: false
32+
33+
- name: Enable KVM
34+
run: |
35+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
36+
sudo udevadm control --reload-rules
37+
sudo udevadm trigger --name-match=kvm
38+
39+
- name: Setup Gradle
40+
uses: gradle/gradle-build-action@v3
41+
42+
- name: Install dependencies
43+
run: yarn --frozen-lockfile
44+
45+
- name: Setup Java
46+
uses: actions/setup-java@v3
47+
with:
48+
cache: gradle
49+
distribution: temurin
50+
java-version: 17
51+
52+
- name: Cache Detox build
53+
id: cache-detox-build
54+
uses: actions/cache@v4
55+
with:
56+
path: android/app/build
57+
key: ${{ runner.os }}-detox-build
58+
restore-keys: |
59+
${{ runner.os }}-detox-build
60+
61+
- name: Detox build
62+
run: yarn e2e:build-android-release
63+
64+
- name: Get device name
65+
id: device
66+
run:
67+
node -e "console.log('AVD_NAME=' + require('./.detoxrc').devices.emulator.device.avdName)" >> $GITHUB_OUTPUT
68+
69+
- name: Detox test
70+
uses: reactivecircus/android-emulator-runner@v2
71+
with:
72+
api-level: 34
73+
arch: x86_64
74+
target: google_apis
75+
disable-animations: true
76+
disk-size: 6000M
77+
heap-size: 600M
78+
avd-name: ${{ steps.device.outputs.AVD_NAME }}
79+
script: yarn e2e:run-android-release --headless --record-logs all
80+
81+
- name: Upload artifacts
82+
if: failure()
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: detox-artifacts
86+
path: artifacts

.github/workflows/e2e_ios.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: E2E iOS
2+
on:
3+
push:
4+
branches:
5+
- master
6+
workflow_call:
7+
8+
jobs:
9+
e2e-ios:
10+
runs-on: macos-12
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
cache: yarn
19+
node-version-file: .node-version
20+
21+
- name: Install dependencies
22+
run: yarn --frozen-lockfile
23+
24+
- name: Install macOS dependencies
25+
run: |
26+
brew tap wix/brew
27+
brew install applesimutils
28+
env:
29+
HOMEBREW_NO_AUTO_UPDATE: 1
30+
HOMEBREW_NO_INSTALL_CLEANUP: 1
31+
32+
- name: Setup Ruby
33+
uses: ruby/setup-ruby@v1
34+
with:
35+
ruby-version: '3.2'
36+
bundler-cache: true
37+
38+
- name: Cache CocoaPods
39+
id: cache-cocoapods
40+
uses: actions/cache@v4
41+
with:
42+
path: ios/Pods
43+
key: ${{ runner.os }}-${{ runner.arch }}-pods-${{ hashFiles('ios/Podfile.lock') }}
44+
restore-keys: |
45+
${{ runner.os }}-${{ runner.arch }}-pods-
46+
47+
- name: Install CocoaPods
48+
run: cd ios ; pod install ; cd -
49+
50+
- name: Detox rebuild framework cache
51+
run: yarn detox rebuild-framework-cache
52+
53+
- name: Cache Detox build
54+
id: cache-detox-build
55+
uses: actions/cache@v4
56+
with:
57+
path: ios/build
58+
key: ${{ runner.os }}-${{ runner.arch }}-detox-build-${{ hashFiles('ios/Podfile.lock') }}
59+
restore-keys: |
60+
${{ runner.os }}-${{ runner.arch }}-detox-build-${{ hashFiles('ios/Podfile.lock') }}
61+
62+
- name: Detox build
63+
run: yarn e2e:build-ios-release
64+
65+
- name: Detox test
66+
run: yarn e2e:run-ios-release --cleanup --headless --record-logs all
67+
68+
- name: Upload artifacts
69+
if: failure()
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: detox-artifacts
73+
path: artifacts

.github/workflows/lint_and_test.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: Lint & Test
2-
32
on: pull_request
43

54
jobs:
@@ -11,8 +10,8 @@ jobs:
1110

1211
- uses: actions/setup-node@v4
1312
with:
14-
node-version: '20'
1513
cache: 'yarn'
14+
node-version-file: .node-version
1615

1716
- name: Install
1817
run: yarn install --frozen-lockfile
@@ -22,3 +21,13 @@ jobs:
2221

2322
- name: Test
2423
run: yarn test
24+
25+
e2e-ios:
26+
needs: build
27+
if: contains(github.event.pull_request.labels.*.name, 'e2e')
28+
uses: ./.github/workflows/e2e_ios.yml
29+
30+
e2e-android:
31+
needs: build
32+
if: contains(github.event.pull_request.labels.*.name, 'e2e')
33+
uses: ./.github/workflows/e2e_android.yml

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ declare module 'react-native-config' {
33
BASE_API_URL?: string;
44
AUTH_STORAGE_KEY?: string;
55
DEFAULT_LOCALE?: string;
6+
MOCK_API?: string;
67
}
78

89
export const Config: NativeConfig;

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { AppRegistry } from 'react-native';
2+
import Config from 'react-native-config';
23

34
import App from './App';
45
import { name as appName } from './app.json';
56

6-
if (process.env.NODE_ENV === 'development') {
7-
require('react-native-url-polyfill/auto');
7+
if (__DEV__ || Config.MOCK_API) {
8+
require('./src/api/mocks/msw.polyfills');
89
const { native } = require('./src/api/mocks/native');
910

1011
native.listen();

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"lint": "tsc && eslint . --ext .js,.jsx,.ts,.tsx",
1212
"postinstall": "npx patch-package",
1313
"clean": "react-native clean --include android,cocoapods,metro,npm,watchman,yarn",
14-
"e2e:build-android-debug": "detox build -c android.emu.debug",
15-
"e2e:build-android-release": "detox build -c android.emu.release",
14+
"e2e:build-android-debug": "ENVFILE=.env.e2e detox build -c android.emu.debug",
15+
"e2e:build-android-release": "ENVFILE=.env.e2e detox build -c android.emu.release",
1616
"e2e:run-android-debug": "detox test -c android.emu.debug",
1717
"e2e:run-android-release": "detox test -c android.emu.release",
18-
"e2e:build-ios-debug": "detox build -c ios.sim.debug",
19-
"e2e:build-ios-release": "detox build -c ios.sim.release",
18+
"e2e:build-ios-debug": "ENVFILE=.env.e2e detox build -c ios.sim.debug",
19+
"e2e:build-ios-release": "ENVFILE=.env.e2e detox build -c ios.sim.release",
2020
"e2e:run-ios-debug": "detox test -c ios.sim.debug",
2121
"e2e:run-ios-release": "detox test -c ios.sim.release"
2222
},
@@ -27,6 +27,7 @@
2727
"@react-navigation/stack": "^6.3.20",
2828
"@tanstack/react-query": "^4.36.1",
2929
"axios": "^1.6.2",
30+
"fast-text-encoding": "^1.0.6",
3031
"nativewind": "^2.0.11",
3132
"qs": "^6.11.2",
3233
"react": "18.2.0",
@@ -38,7 +39,8 @@
3839
"react-native-mmkv": "^2.11.0",
3940
"react-native-reanimated": "^3.6.1",
4041
"react-native-safe-area-context": "^4.7.4",
41-
"react-native-screens": "^3.27.0"
42+
"react-native-screens": "^3.27.0",
43+
"react-native-url-polyfill": "^2.0.0"
4244
},
4345
"devDependencies": {
4446
"@babel/core": "^7.23.2",
@@ -59,16 +61,15 @@
5961
"@types/react-test-renderer": "^18.0.3",
6062
"babel-jest": "^29.7.0",
6163
"babel-plugin-module-resolver": "^5.0.0",
62-
"detox": "^20.13.4",
64+
"detox": "^20.20.2",
6365
"eslint": "^8.19.0",
6466
"eslint-config-prettier": "^8.3.0",
6567
"eslint-plugin-import": "^2.25.3",
6668
"eslint-plugin-prettier": "^4.0.0",
6769
"eslint-plugin-react-native": "^4.1.0",
6870
"jest": "^29.7.0",
69-
"msw": "1.3.2",
71+
"msw": "2.2.13",
7072
"prettier": "2.8.8",
71-
"react-native-url-polyfill": "^1.3.0",
7273
"react-test-renderer": "18.2.0",
7374
"tailwindcss": "3.3.2",
7475
"ts-jest": "^29.1.1",

0 commit comments

Comments
 (0)