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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 0 additions & 1 deletion
This file was deleted.

App.tsx

Lines changed: 5 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 13 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 52 deletions
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'

0 commit comments

Comments
 (0)