-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
louiszawadzki
committed
Jan 16, 2024
1 parent
0fd51e6
commit 175600d
Showing
35 changed files
with
1,995 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/internal-testing-tools/DatadogInternalTesting.podspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require "json" | ||
|
||
package = JSON.parse(File.read(File.join(__dir__, "package.json"))) | ||
|
||
Pod::Spec.new do |s| | ||
s.name = "DatadogInternalTesting" | ||
s.version = package["version"] | ||
s.summary = package["description"] | ||
s.homepage = package["homepage"] | ||
s.license = package["license"] | ||
s.authors = package["author"] | ||
|
||
s.platforms = { :ios => "11.0", :tvos => "11.0" } | ||
s.source = { :git => "https://github.com/DataDog/dd-sdk-reactnative.git", :tag => "#{s.version}" } | ||
|
||
|
||
s.source_files = "ios/Sources/*.{h,m,mm,swift}" | ||
|
||
s.dependency "React-Core" | ||
|
||
# This guard prevents installing the dependencies when we run `pod install` in the old architecture. | ||
# The `install_modules_dependencies` function is only available from RN 0.71, the new architecture is not | ||
# supported on earlier RN versions. | ||
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then | ||
s.pod_target_xcconfig = { | ||
"DEFINES_MODULE" => "YES", | ||
"OTHER_CPLUSPLUSFLAGS" => "-DRCT_NEW_ARCH_ENABLED=1" | ||
} | ||
|
||
install_modules_dependencies(s) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Internal E2E testing tools | ||
|
||
This package is internal and not released on npm. | ||
It contains tools for our E2E tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
import type { NativeInternalTestingType } from '../src/nativeModulesTypes'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const actualRN = require('react-native'); | ||
|
||
actualRN.NativeModules.DdInternalTesting = { | ||
enable: jest.fn().mockImplementation( | ||
() => new Promise<void>(resolve => resolve()) | ||
) as jest.MockedFunction<NativeInternalTestingType['enable']> | ||
}; | ||
|
||
module.exports = actualRN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
import java.nio.file.Paths | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
buildscript { | ||
// Buildscript is evaluated before everything else so we can't use getExtOrDefault | ||
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['DatadogInternalTesting_kotlinVersion'] | ||
|
||
repositories { | ||
mavenCentral() | ||
google() | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:7.2.2' | ||
// noinspection DifferentKotlinGradleVersion | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
classpath "org.jlleitschuh.gradle:ktlint-gradle:11.5.1" | ||
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.0" | ||
classpath 'com.github.bjoernq:unmockplugin:0.7.9' | ||
} | ||
} | ||
|
||
|
||
apply plugin: 'de.mobilej.unmock' | ||
|
||
def isNewArchitectureEnabled() { | ||
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
if (isNewArchitectureEnabled()) { | ||
apply plugin: 'com.facebook.react' | ||
} | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'org.jlleitschuh.gradle.ktlint' | ||
apply plugin: "io.gitlab.arturbosch.detekt" | ||
|
||
/** | ||
* Finds the path of the installed npm package with the given name using Node's | ||
* module resolution algorithm, which searches "node_modules" directories up to | ||
* the file system root. | ||
* This enables us to handle monorepos without requiring the node executable. | ||
* | ||
* The search begins at the given base directory (a File object). The returned | ||
* path is a string. | ||
*/ | ||
static def findNodeModulePath(baseDir, packageName) { | ||
def basePath = baseDir.toPath().normalize() | ||
// Node's module resolution algorithm searches up to the root directory, | ||
// after which the base path will be null | ||
while (basePath) { | ||
def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName) | ||
if (candidatePath.toFile().exists()) { | ||
return candidatePath.toString() | ||
} | ||
basePath = basePath.getParent() | ||
} | ||
return null | ||
} | ||
|
||
def resolveReactNativeDirectory() { | ||
def reactNativeLocation = rootProject.hasProperty("reactNativeDir") ? rootProject.getProperty("reactNativeDir") : null | ||
|
||
if (reactNativeLocation != null) { | ||
return file(reactNativeLocation) | ||
} | ||
|
||
def reactNativePath = findNodeModulePath(projectDir, "react-native") | ||
|
||
if (reactNativePath != null) { | ||
return file(reactNativePath) | ||
} | ||
|
||
throw new Exception( | ||
"${project.name}: Failed to resolve 'react-native' in the project. " + | ||
"Altenatively, you can specify 'reactNativeDir' with the path to 'react-native' in your 'gradle.properties' file." | ||
) | ||
} | ||
|
||
def reactNativeRootDir = resolveReactNativeDirectory() | ||
def reactProperties = new Properties() | ||
file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) } | ||
|
||
def reactNativeVersion = reactProperties.getProperty("VERSION_NAME") | ||
def (reactNativeMajorVersion, reactNativeMinorVersion) = reactNativeVersion.split("\\.").collect { it.isInteger() ? it.toInteger() : it } | ||
|
||
def getExtOrDefault(name) { | ||
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['DatadogInternalTesting_' + name] | ||
} | ||
|
||
def getExtOrIntegerDefault(name) { | ||
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['DatadogInternalTesting_' + name]).toInteger() | ||
} | ||
|
||
android { | ||
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') | ||
buildToolsVersion getExtOrDefault('buildToolsVersion') | ||
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION | ||
if (agpVersion.tokenize('.')[0].toInteger() >= 7) { | ||
namespace = "com.datadog.reactnative.internaltesting" | ||
} | ||
if (agpVersion.tokenize('.')[0].toInteger() >= 8) { | ||
buildFeatures { | ||
buildConfig = true | ||
} | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') | ||
versionCode 1 | ||
versionName "1.0" | ||
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()) | ||
} | ||
|
||
sourceSets { | ||
main { | ||
if (isNewArchitectureEnabled()) { | ||
java.srcDirs += ['src/newarch/kotlin'] | ||
} else { | ||
java.srcDirs += ['src/oldarch/kotlin'] | ||
} | ||
} | ||
test { | ||
java.srcDir("src/test/kotlin") | ||
} | ||
} | ||
|
||
testOptions { | ||
unitTests { | ||
returnDefaultValues = true | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
} | ||
} | ||
lintOptions { | ||
disable 'GradleCompatible' | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_11 | ||
targetCompatibility JavaVersion.VERSION_11 | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
google() | ||
maven { url "https://jitpack.io" } | ||
mavenLocal() | ||
|
||
if (reactNativeMajorVersion == 0 && reactNativeMinorVersion < 71) { | ||
def androidSourcesDir = file("$reactNativeRootDir/android") | ||
def androidSourcesName = "React Native sources" | ||
|
||
if (androidSourcesDir.exists()) { | ||
maven { | ||
url androidSourcesDir.toString() | ||
name androidSourcesName | ||
} | ||
} | ||
} | ||
} | ||
|
||
def kotlin_version = getExtOrDefault('kotlinVersion') | ||
|
||
dependencies { | ||
if (reactNativeMajorVersion == 0 && reactNativeMinorVersion < 71) { | ||
// noinspection GradleDynamicVersion | ||
api 'com.facebook.react:react-native:+' | ||
} else { | ||
// We specify the $reactNativeVersion, like it's done on the react-native-gradle-plugin, as the plugin is not applied in tests. | ||
// There is no impact for apps as we apply the same logic: | ||
// https://github.com/facebook/react-native/blob/e1a1e6aa8030bf11d691c3dcf7abd13b25175027/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt | ||
api "com.facebook.react:react-android:$reactNativeVersion" | ||
} | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
|
||
testImplementation "org.junit.platform:junit-platform-launcher:1.6.2" | ||
testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2" | ||
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2" | ||
testImplementation "org.junit.jupiter:junit-jupiter-params:5.6.2" | ||
testImplementation "org.mockito:mockito-junit-jupiter:3.4.6" | ||
testImplementation "org.assertj:assertj-core:3.18.1" | ||
testImplementation "com.github.xgouchet.Elmyr:core:1.3.1" | ||
testImplementation "com.github.xgouchet.Elmyr:inject:1.3.1" | ||
testImplementation "com.github.xgouchet.Elmyr:junit5:1.3.1" | ||
testImplementation "com.github.xgouchet.Elmyr:jvm:1.3.1" | ||
testImplementation "org.mockito.kotlin:mockito-kotlin:5.1.0" | ||
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" | ||
unmock 'org.robolectric:android-all:4.4_r1-robolectric-r2' | ||
} | ||
|
||
tasks.withType(Test) { | ||
tasks.withType(KotlinCompile) { | ||
kotlinOptions.jvmTarget = JavaVersion.VERSION_11 | ||
} | ||
|
||
useJUnitPlatform { | ||
includeEngines("spek", "junit-jupiter", "junit-vintage") | ||
} | ||
reports { | ||
junitXml.required.set(true) | ||
html.required.set(true) | ||
} | ||
} | ||
|
||
tasks.named("check") { | ||
dependsOn("ktlintCheck") | ||
dependsOn("detekt") | ||
} | ||
|
||
ktlint { | ||
debug.set(false) | ||
android.set(true) | ||
outputToConsole.set(true) | ||
ignoreFailures.set(false) | ||
enableExperimentalRules.set(false) | ||
filter { | ||
exclude("**/generated/**") | ||
include("**/kotlin/**") | ||
} | ||
} | ||
|
||
detekt { | ||
input = files("$projectDir/src/main/kotlin") | ||
config = files("$projectDir/detekt.yml") | ||
reports { | ||
xml { | ||
enabled = true | ||
destination = file("build/reports/detekt.xml") | ||
} | ||
} | ||
} |
Oops, something went wrong.