Skip to content

Commit

Permalink
Merge pull request #4649 from wix/feat/rn75
Browse files Browse the repository at this point in the history
Feat/rn75
  • Loading branch information
gosha212 authored Dec 4, 2024
2 parents c731d88 + c93ecf6 commit aa40512
Show file tree
Hide file tree
Showing 47 changed files with 538 additions and 316 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- label: ":android::react: RN .74 + Android: Demo app"
- label: ":android::react: RN .75 + Android: Demo app"
command:
- "nvm install"
- "./scripts/demo-projects.android.sh"
env:
REACT_NATIVE_VERSION: 0.74.6
REACT_NATIVE_VERSION: 0.75.4
REACT_NATIVE_COMPAT_TEST: true # Only set 'true' in jobs with the latest supported RN
DETOX_DISABLE_POD_INSTALL: true
DETOX_DISABLE_POSTINSTALL: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- label: ":android::detox: RN .74 + Android: Tests app"
- label: ":android::detox: RN .75 + Android: Tests app"
command:
- "nvm install"
- "./scripts/ci.android.sh"
env:
REACT_NATIVE_VERSION: 0.74.6
REACT_NATIVE_VERSION: 0.75.4
DETOX_DISABLE_POD_INSTALL: true
DETOX_DISABLE_POSTINSTALL: true
artifact_paths:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- label: ":ios::react: RN .74 + iOS: Demo app"
- label: ":ios::react: RN .75 + iOS: Demo app"
command:
- "nvm install"
- "./scripts/demo-projects.ios.sh"
env:
REACT_NATIVE_VERSION: 0.74.6
REACT_NATIVE_VERSION: 0.75.4
artifact_paths:
- "/Users/builder/uibuilder/work/coverage/**/*.lcov"
- "/Users/builder/uibuilder/work/artifacts*.tar.gz"
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- label: ":ios::detox: RN .74 + iOS: Tests app"
- label: ":ios::detox: RN .75 + iOS: Tests app"
command:
- "nvm install"
- "./scripts/ci.ios.sh"
env:
REACT_NATIVE_VERSION: 0.74.6
REACT_NATIVE_VERSION: 0.75.4
artifact_paths:
- "/Users/builder/uibuilder/work/coverage/**/*.lcov"
- "/Users/builder/uibuilder/work/**/allure-report-*.html"
Expand Down
8 changes: 4 additions & 4 deletions .buildkite/pipeline_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

echo "steps:"

cat .buildkite/jobs/pipeline.ios_rn_74.yml
cat .buildkite/jobs/pipeline.ios_rn_75.yml
cat .buildkite/jobs/pipeline.ios_rn_73.yml
cat .buildkite/jobs/pipeline.ios_demo_app_rn_74.yml
cat .buildkite/jobs/pipeline.ios_demo_app_rn_75.yml
cat .buildkite/jobs/pipeline.ios_demo_app_rn_73.yml
cat .buildkite/jobs/pipeline.android_rn_74.yml
cat .buildkite/jobs/pipeline.android_rn_75.yml
cat .buildkite/jobs/pipeline.android_rn_73.yml
cat .buildkite/jobs/pipeline.android_demo_app_rn_74.yml
cat .buildkite/jobs/pipeline.android_demo_app_rn_75.yml
cat .buildkite/pipeline.post_processing.yml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ The most difficult part of automated testing on mobile is the tip of the testing

Detox was built from the ground up to support React Native projects.

While Detox should work out of the box with almost any React Native version of the latest minor releases, official support is provided for React Native versions `0.71.x`, `0.72.x`, `0.73.x`, `0.74.x` without React Native's ["New Architecture"](https://reactnative.dev/docs/the-new-architecture/landing-page).
While Detox should work out of the box with almost any React Native version of the latest minor releases, official support is provided for React Native versions `0.72.x`, `0.73.x`, `0.74.x`, `0.75.x` with or without React Native's ["New Architecture"](https://reactnative.dev/docs/the-new-architecture/landing-page).

Newer versions, as well as React Native's "New Architecture", may work with Detox, but have not been tested out yet by the Detox team.

Expand Down
2 changes: 1 addition & 1 deletion detox/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {

ext {
isOfficialDetoxLib = true
kotlinVersion = '1.9.20'
kotlinVersion = '1.9.24'
dokkaVersion = '1.9.10'
buildToolsVersion = '34.0.0'
compileSdkVersion = 34
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.wix.detox.espresso.web;


import static androidx.test.espresso.web.webdriver.DriverAtoms.findMultipleElements;

import androidx.test.espresso.web.model.Atom;
import androidx.test.espresso.web.model.ElementReference;
import androidx.test.espresso.web.webdriver.Locator;

import java.util.List;

import static androidx.test.espresso.web.webdriver.DriverAtoms.findMultipleElements;

public class DetoxWebAtomMatcher {

private DetoxWebAtomMatcher() {
Expand Down Expand Up @@ -46,4 +46,4 @@ public static Atom<List<ElementReference>> matcherForPartialLinkText(String part
public static Atom<List<ElementReference>> matcherForTagName(String tag) {
return findMultipleElements(Locator.TAG_NAME, tag);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import androidx.test.espresso.web.model.Atom;
import androidx.test.espresso.web.model.Atoms;
import androidx.test.espresso.web.model.ElementReference;
import androidx.test.espresso.web.model.Evaluation;
import androidx.test.espresso.web.model.SimpleAtom;
import androidx.test.espresso.web.sugar.Web;
import androidx.test.espresso.web.webdriver.DriverAtoms;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,55 @@
package com.wix.detox.espresso.web;

import static androidx.test.espresso.web.sugar.Web.onWebView;

import android.view.View;
import android.webkit.WebView;

import androidx.test.espresso.web.model.Atom;
import androidx.test.espresso.web.model.ElementReference;
import androidx.test.espresso.web.sugar.Web;

import org.hamcrest.CoreMatchers;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import java.util.List;

import javax.annotation.Nullable;

import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.web.sugar.Web.onWebView;
import static org.hamcrest.CoreMatchers.allOf;

public class WebViewElement {

final Matcher<View> matcher;
private final static String WRAPPER_WEBVIEW_CLASS_NAME = "RNCWebViewWrapper";

final Web.WebInteraction<Void> webViewInteraction;

WebViewElement(@Nullable Matcher<View> matcher) {
this.matcher = matcher != null ? matcher : allOf(CoreMatchers.<View>instanceOf(WebView.class), isDisplayed());
WebViewElement(@Nullable Matcher<View> userMatcher) {
Matcher<View> matcher = null;

if (userMatcher != null) {
matcher = new TypeSafeMatcher<>() {

@Override
protected boolean matchesSafely(View item) {
// Support for react-native-webview >= 13.0.0
if (item instanceof WebView && item.getParent().getClass().getSimpleName().equals(WRAPPER_WEBVIEW_CLASS_NAME)) {
return userMatcher.matches(item.getParent());
}

if (item.getClass().getSimpleName().equals("RNCWebViewWrapper")) {
// We never want to match the wrapper of the webview
return false;
}

return userMatcher.matches(item);
}

@Override
public void describeTo(Description description) {
userMatcher.describeTo(description);
}
};
}
this.webViewInteraction = matcher != null ? onWebView(matcher) : onWebView();
}

Expand Down
2 changes: 1 addition & 1 deletion detox/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 1 addition & 0 deletions detox/android/rninfo.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ ext.rnInfo = [
isRN72OrHigher: rnMajorVer >= 72,
isRN73OrHigher: rnMajorVer >= 73,
isRN74OrHigher: rnMajorVer >= 74,
isRN75OrHigher: rnMajorVer >= 75,
]
9 changes: 8 additions & 1 deletion detox/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// RN75+_BLOCK_START
pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") }
plugins { id("com.facebook.react.settings") }
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
// RN75+_BLOCK_END


apply from: '../android/rninfo.gradle'
include ':detox'

println("RNInfo: rootDir=$rootDir")

println "[settings] RNInfo: detected React Native version: (major=${ext.rnInfo.version})"


if (ext.rnInfo.isRN72OrHigher) {
includeBuild('../node_modules/@react-native/gradle-plugin')
} else {
Expand Down
10 changes: 5 additions & 5 deletions detox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"postinstall": "node scripts/postinstall.js"
},
"devDependencies": {
"@react-native/babel-preset": "0.74.88",
"@react-native/eslint-config": "0.74.88",
"@react-native/metro-config": "0.74.88",
"@react-native/typescript-config": "0.74.88",
"@react-native/babel-preset": "0.75.4",
"@react-native/eslint-config": "0.75.4",
"@react-native/metro-config": "0.75.4",
"@react-native/typescript-config": "0.75.4",
"@tsconfig/react-native": "^3.0.0",
"@types/bunyan": "^1.8.8",
"@types/child-process-promise": "^2.2.1",
Expand All @@ -59,7 +59,7 @@
"jest-allure2-reporter": "^2.0.0-beta.18",
"metro-react-native-babel-preset": "0.76.8",
"prettier": "^3.1.1",
"react-native": "0.74.6",
"react-native": "0.75.4",
"react-native-codegen": "^0.0.8",
"typescript": "^5.3.3",
"wtfnode": "^0.9.1"
Expand Down
4 changes: 2 additions & 2 deletions detox/scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { platform, env } = process;

const { setGradleVersionByRNVersion } = require('./updateGradle');
const { patchGradleByRNVersion } = require('./updateGradle');

const isDarwin = platform === 'darwin';
const shouldInstallDetox = !env.DETOX_DISABLE_POSTINSTALL;
Expand All @@ -12,4 +12,4 @@ if (isDarwin && shouldInstallDetox) {
execFileSync(`${__dirname}/build_local_xcuitest.ios.sh`, { stdio: 'inherit' });
}

setGradleVersionByRNVersion();
patchGradleByRNVersion();
43 changes: 36 additions & 7 deletions detox/scripts/updateGradle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const rnMinor = require('../src/utils/rn-consts/rn-consts').rnVersion.minor;
function getGradleVersionByRNVersion() {
switch (rnMinor) {
default:
return '8.8';
case '74':
return '8.6';
case '73':
return '8.3';
Expand All @@ -19,17 +21,44 @@ function getGradleVersionByRNVersion() {
/**
* Update the Gradle wrapper to the version that matches the React Native version.
*/
function setGradleVersionByRNVersion() {
const gradleVersion = getGradleVersionByRNVersion();
updateGradleWrapperSync(gradleVersion);
function patchGradleByRNVersion() {
updateGradleWrapperSync();
patchSettingsGradle();
}

/**
* In RN75 and above the settings.gradle file should contain the following lines. We can't wrap them in 'if' statement
* because they should be the first line in the settings file. This patch could be safely removed after dropping support
* for RN74.
*/
function patchSettingsGradle() {
if (parseInt(rnMinor) >= 75) {
return;
}

const settingsGradlePath = path.join(process.cwd(), 'android', 'settings.gradle');
console.log(`Patching settings.gradle. File: ${settingsGradlePath}`);

try {
let data = fs.readFileSync(settingsGradlePath, 'utf8');
const blockRegex = /\/\/ RN75\+_BLOCK_START[\s\S]*?\/\/ RN75\+_BLOCK_END/g;

// Replace the block with an empty string
const updatedData = data.replace(blockRegex, '');

fs.writeFileSync(settingsGradlePath, updatedData, 'utf8');
console.log('settings.gradle patched successfully.');
} catch (err) {
console.error('Error:', err);
}
}

/**
* Update the Gradle wrapper to the specified version.
*
* @param {string} newVersion - the new Gradle wrapper version
*/
function updateGradleWrapperSync(newVersion) {
function updateGradleWrapperSync() {
const newVersion = getGradleVersionByRNVersion();

const gradleWrapperPath = path.join(process.cwd(), 'android', 'gradle', 'wrapper', 'gradle-wrapper.properties');
console.log(`Updating Gradle wrapper to version$ {newVersion}. File: ${gradleWrapperPath}`);

Expand All @@ -45,5 +74,5 @@ function updateGradleWrapperSync(newVersion) {
}

module.exports = {
setGradleVersionByRNVersion
patchGradleByRNVersion: patchGradleByRNVersion
};
19 changes: 10 additions & 9 deletions detox/test/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ apply plugin: 'com.facebook.react'
apply plugin: 'kotlin-android'
apply from: '../../../android/rninfo.gradle'

react {
if (rnInfo.isRN75OrHigher) {
autolinkLibrariesWithApp()
}
}

android {
namespace 'com.example'
Expand Down Expand Up @@ -100,15 +105,6 @@ dependencies {
implementation "androidx.appcompat:appcompat:${rootProject.ext.appCompatVersion}"
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

implementation project(path: ':@react-native-community_slider')
implementation project(':AsyncStorage')
implementation project(':react-native-webview')
implementation project(':react-native-community-checkbox')
implementation project(':react-native-community-geolocation')
implementation project(':react-native-datetimepicker')
implementation project(':react-native-launcharguments')
implementation project(':react-native-permissions')

androidTestImplementation(project(path: ':detox'))
androidTestImplementation 'com.github.wix-incubator:detox-butler:1.0.4'
}
Expand All @@ -124,3 +120,8 @@ task copyDownloadableDepsToLibs(type: Copy) {
from configurations.implementation
into 'libs'
}

if (!ext.rnInfo.isRN75OrHigher) {
// For versions below 0.75, we need to apply the old plugin
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
}
40 changes: 0 additions & 40 deletions detox/test/android/app/src/main/java/com/example/DetoxRNHost.java

This file was deleted.

Loading

0 comments on commit aa40512

Please sign in to comment.