Skip to content

Commit a38506e

Browse files
authored
rn upgrade & maestro e2e tests (#44)
* rn upgrade & maestro e2e tests * readme update how to run E2E tests * adding modal screen test * e2e tests completion * unit test fix and libs upgrade * record command addition * docs: add gif of app impression
1 parent 7cb5c73 commit a38506e

34 files changed

+4639
-2398
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
root: true,
3-
extends: '@react-native-community',
3+
extends: '@react-native',
44
};

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ yarn-error.log
6161

6262
# Temporary files created by Metro to check the health of the file watcher
6363
.metro-health-check*
64+
65+
# testing
66+
/coverage

.node-version

-1
This file was deleted.

App.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ export default () => {
5050
<>
5151
<ThemeProvider initialTheme={'dark'}>
5252
<NavigationContainer>
53-
<Stack.Navigator initialRouteName="Home">
53+
<Stack.Navigator
54+
initialRouteName="Home"
55+
screenOptions={{
56+
headerBackTestID: 'go-back-home-button',
57+
}}>
5458
<Stack.Screen name={SCREENS.HOME} component={Home} />
5559
<Stack.Screen name={SCREENS.LOGIN} component={LoginSubmission} />
5660
<Stack.Screen

Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'https://rubygems.org'
22

33
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4-
ruby '>= 2.6.10'
4+
ruby ">= 2.6.10"
55

6-
gem 'cocoapods', '>= 1.11.3'
6+
gem 'cocoapods', '~> 1.12'

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ PLATFORMS
8989
ruby
9090

9191
DEPENDENCIES
92-
cocoapods (>= 1.11.3)
92+
cocoapods (~> 1.12)
9393

9494
RUBY VERSION
9595
ruby 2.7.5p203

README.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@
2020
### Tools in use 🛠️
2121
- [Jest](https://jestjs.io/)
2222
- [React Native Testing Library](https://callstack.github.io/react-native-testing-library/)
23+
- [Maestro](https://maestro.mobile.dev/)
2324

25+
### Setup and requirements 📋
26+
- [RN- Setting up the development environment](https://reactnative.dev/docs/environment-setup)
27+
- [Installing Maestro](https://maestro.mobile.dev/getting-started/installing-maestro)
2428

2529
### How to run the tests 🏃‍♀️
2630
- Clone the repo
2731
- Run `yarn` to install dependencies
28-
- Run `yarn test` to run the tests
29-
- Run `yarn test:coverage` to run the tests and generate a coverage report
30-
32+
- Run `yarn test:unit` to run the unit tests
33+
- Run `yarn test:unit:dev` to run the unit tests in dev/watch mode
34+
- Run `yarn test:unit:coverage` to run the tests and generate a coverage report
35+
- Run `yarn test:e2e` to run the e2e tests
36+
- Run `yarn test:e2e:dev` to run the e2e tests in dev/watch mode
37+
- Run `yarn test:e2e:record` to run the e2e tests and record a video of the tests
3138

3239
### How to run the app 📱
3340
- Clone the repo
@@ -37,7 +44,6 @@
3744
- Click `i` to run the app on iOS simulator or `a` to run it on Android emulator
3845

3946
### Ideas and future improvements 🚀
40-
- 📱 Add E2E tests with Maestro
4147
- ⚛️ Add tests for react native web project
4248

4349
### Inspiration, resources and further reading 📚
@@ -50,3 +56,6 @@ For more info check [Epic React](https://epicreact.dev/).
5056
- 🗺 [React Navigation](https://reactnavigation.org/)
5157
- 🛰 [MSW](https://mswjs.io/)
5258

59+
- #### Impression of the the project 📸
60+
61+
![app-in-e2e-testing-gif](https://github.com/vanGalilea/react-native-testing/assets/25864161/7015cb21-5347-453a-aee7-4f848ae7a780)

__tests__/EasyButton.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ it.each(cases)(
2424
theme: desiredTheme,
2525
});
2626
const innerText = screen.getByText(/click me/i);
27-
const pressable = screen.getByLabelText('easy-button');
27+
const pressable = screen.getByRole('button');
2828
expect(pressable).toHaveStyle({
2929
backgroundColor: expectedBackground,
3030
});

__tests__/ListWithFetch.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test('displays images from the server', async () => {
3434
test('displays error upon error response from server', async () => {
3535
// Simulate an error response from the server
3636
server.resetHandlers(
37-
rest.get('https://fakerapi.it/api/v1/users', (res, req, ctx) => {
37+
rest.get('https://dummyjson.com/users', (res, req, ctx) => {
3838
// @ts-ignore
3939
res(ctx.status(500));
4040
}),

android/app/build.gradle

+2-52
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
apply plugin: "com.android.application"
22
apply plugin: "com.facebook.react"
33

4-
import com.android.build.OutputFile
5-
64
/**
75
* This is the configuration block to customize your React Native Android app.
86
* By default you don't need to apply any configuration, just uncomment the lines you need.
@@ -11,10 +9,8 @@ react {
119
/* Folders */
1210
// The root of your project, i.e. where "package.json" lives. Default is '..'
1311
// root = file("../")
14-
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
15-
// reactNativeDir = file("../node_modules/react-native")
16-
// The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
17-
// codegenDir = file("../node_modules/react-native-codegen")
12+
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
13+
// codegenDir = file("../node_modules/@react-native/codegen")
1814
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
1915
// cliFile = file("../node_modules/react-native/cli.js")
2016

@@ -52,14 +48,6 @@ react {
5248
// hermesFlags = ["-O", "-output-source-map"]
5349
}
5450

55-
/**
56-
* Set this to true to create four separate APKs instead of one,
57-
* one for each native architecture. This is useful if you don't
58-
* use App Bundles (https://developer.android.com/guide/app-bundle/)
59-
* and want to have separate APKs to upload to the Play Store.
60-
*/
61-
def enableSeparateBuildPerCPUArchitecture = false
62-
6351
/**
6452
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
6553
*/
@@ -78,16 +66,6 @@ def enableProguardInReleaseBuilds = false
7866
*/
7967
def jscFlavor = 'org.webkit:android-jsc:+'
8068

81-
/**
82-
* Private function to get the list of Native Architectures you want to build.
83-
* This reads the value from reactNativeArchitectures in your gradle.properties
84-
* file and works together with the --active-arch-only flag of react-native run-android.
85-
*/
86-
def reactNativeArchitectures() {
87-
def value = project.getProperties().get("reactNativeArchitectures")
88-
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
89-
}
90-
9169
android {
9270
ndkVersion rootProject.ext.ndkVersion
9371

@@ -101,15 +79,6 @@ android {
10179
versionCode 1
10280
versionName "1.0"
10381
}
104-
105-
splits {
106-
abi {
107-
reset()
108-
enable enableSeparateBuildPerCPUArchitecture
109-
universalApk false // If true, also generate a universal APK
110-
include (*reactNativeArchitectures())
111-
}
112-
}
11382
signingConfigs {
11483
debug {
11584
storeFile file('debug.keystore')
@@ -130,30 +99,11 @@ android {
13099
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
131100
}
132101
}
133-
134-
// applicationVariants are e.g. debug, release
135-
applicationVariants.all { variant ->
136-
variant.outputs.each { output ->
137-
// For each separate APK per architecture, set a unique version code as described here:
138-
// https://developer.android.com/studio/build/configure-apk-splits.html
139-
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
140-
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
141-
def abi = output.getFilter(OutputFile.ABI)
142-
if (abi != null) { // null for the universal-debug, universal-release variants
143-
output.versionCodeOverride =
144-
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
145-
}
146-
147-
}
148-
}
149102
}
150103

151104
dependencies {
152105
// The version of react-native is set by the React Native Gradle Plugin
153106
implementation("com.facebook.react:react-android")
154-
155-
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
156-
157107
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
158108
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
159109
exclude group:'com.squareup.okhttp3', module:'okhttp'

android/app/src/main/java/com/reactnativetesting/MainActivity.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ protected ReactActivityDelegate createReactActivityDelegate() {
2727
this,
2828
getMainComponentName(),
2929
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
30-
DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled
31-
// If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18).
32-
DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled
33-
);
30+
DefaultNewArchitectureEntryPoint.getFabricEnabled()
31+
);
3432
}
3533
}

android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ buildscript {
1515
mavenCentral()
1616
}
1717
dependencies {
18-
classpath("com.android.tools.build:gradle:7.3.1")
18+
classpath("com.android.tools.build:gradle")
1919
classpath("com.facebook.react:react-native-gradle-plugin")
2020
}
2121
}

android/gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ android.useAndroidX=true
2525
android.enableJetifier=true
2626

2727
# Version of flipper SDK to use with React Native
28-
FLIPPER_VERSION=0.125.0
28+
FLIPPER_VERSION=0.182.0
2929

3030
# Use this property to specify which architecture you want to build.
3131
# You can also override it from the CLI using
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip
4+
networkTimeout=10000
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

android/gradlew

+14-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Darwin, MinGW, and NonStop.
5656
#
5757
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
58+
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5959
# within the Gradle project.
6060
#
6161
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,10 +80,10 @@ do
8080
esac
8181
done
8282

83-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84-
85-
APP_NAME="Gradle"
83+
# This is normally unused
84+
# shellcheck disable=SC2034
8685
APP_BASE_NAME=${0##*/}
86+
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
8787

8888
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
8989
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
@@ -143,12 +143,16 @@ fi
143143
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144144
case $MAX_FD in #(
145145
max*)
146+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147+
# shellcheck disable=SC3045
146148
MAX_FD=$( ulimit -H -n ) ||
147149
warn "Could not query maximum file descriptor limit"
148150
esac
149151
case $MAX_FD in #(
150152
'' | soft) :;; #(
151153
*)
154+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155+
# shellcheck disable=SC3045
152156
ulimit -n "$MAX_FD" ||
153157
warn "Could not set maximum file descriptor limit to $MAX_FD"
154158
esac
@@ -205,6 +209,12 @@ set -- \
205209
org.gradle.wrapper.GradleWrapperMain \
206210
"$@"
207211

212+
# Stop when "xargs" is not available.
213+
if ! command -v xargs >/dev/null 2>&1
214+
then
215+
die "xargs is not available"
216+
fi
217+
208218
# Use "xargs" to parse quoted args.
209219
#
210220
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

android/gradlew.bat

+9-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@rem limitations under the License.
1515
@rem
1616

17-
@if "%DEBUG%" == "" @echo off
17+
@if "%DEBUG%"=="" @echo off
1818
@rem ##########################################################################
1919
@rem
2020
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
2525
if "%OS%"=="Windows_NT" setlocal
2626

2727
set DIRNAME=%~dp0
28-
if "%DIRNAME%" == "" set DIRNAME=.
28+
if "%DIRNAME%"=="" set DIRNAME=.
29+
@rem This is normally unused
2930
set APP_BASE_NAME=%~n0
3031
set APP_HOME=%DIRNAME%
3132

@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4041

4142
set JAVA_EXE=java.exe
4243
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
44+
if %ERRORLEVEL% equ 0 goto execute
4445

4546
echo.
4647
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7576

7677
:end
7778
@rem End local scope for the variables with windows NT shell
78-
if "%ERRORLEVEL%"=="0" goto mainEnd
79+
if %ERRORLEVEL% equ 0 goto mainEnd
7980

8081
:fail
8182
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
8283
rem the _cmd.exe /c_ return code!
83-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84-
exit /b 1
84+
set EXIT_CODE=%ERRORLEVEL%
85+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
86+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87+
exit /b %EXIT_CODE%
8588

8689
:mainEnd
8790
if "%OS%"=="Windows_NT" endlocal

android/settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
rootProject.name = 'reactnativetesting'
22
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
33
include ':app'
4-
includeBuild('../node_modules/react-native-gradle-plugin')
4+
includeBuild('../node_modules/@react-native/gradle-plugin')

0 commit comments

Comments
 (0)