Skip to content

Commit 18d1c2f

Browse files
authored
Merge pull request #12 from BlackishGreen33/bg/native/regression-coverage
test(plugin): expand Android and AppDelegate regression coverage
2 parents 2e7a1ba + eee3e3d commit 18d1c2f

11 files changed

Lines changed: 735 additions & 18 deletions

File tree

plugin/__tests__/androidFixture.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { compileModsAsync } from 'expo/config-plugins';
2+
import * as fs from 'fs';
3+
import * as os from 'os';
4+
import * as path from 'path';
5+
import withJPush from '../src';
6+
import { JPushPluginProps } from '../src/types';
7+
import { createExpoConfig, createPluginProps } from './testProps';
8+
9+
export const FIXTURE_ROOT = path.join(__dirname, 'fixtures', 'android-project');
10+
export const APP_BUILD_GRADLE_PATH = ['android', 'app', 'build.gradle'];
11+
export const ANDROID_MANIFEST_PATH = [
12+
'android',
13+
'app',
14+
'src',
15+
'main',
16+
'AndroidManifest.xml',
17+
];
18+
export const PROJECT_BUILD_GRADLE_PATH = ['android', 'build.gradle'];
19+
export const SETTINGS_GRADLE_PATH = ['android', 'settings.gradle'];
20+
export const GRADLE_PROPERTIES_PATH = ['android', 'gradle.properties'];
21+
22+
const tempProjectRoots: string[] = [];
23+
24+
export function registerAndroidFixtureLifecycleHooks(): void {
25+
beforeEach(() => {
26+
jest.spyOn(console, 'log').mockImplementation(() => {});
27+
});
28+
29+
afterEach(() => {
30+
jest.restoreAllMocks();
31+
32+
while (tempProjectRoots.length > 0) {
33+
const projectRoot = tempProjectRoots.pop();
34+
if (projectRoot) {
35+
fs.rmSync(projectRoot, { recursive: true, force: true });
36+
}
37+
}
38+
});
39+
}
40+
41+
export function getFixturePath(projectRoot: string, segments: string[]): string {
42+
return path.join(projectRoot, ...segments);
43+
}
44+
45+
export function createProjectRoot(): string {
46+
const projectRoot = fs.mkdtempSync(
47+
path.join(os.tmpdir(), 'mx-jpush-android-')
48+
);
49+
fs.cpSync(FIXTURE_ROOT, projectRoot, { recursive: true });
50+
tempProjectRoots.push(projectRoot);
51+
return projectRoot;
52+
}
53+
54+
export function readFixtureFile(
55+
projectRoot: string,
56+
segments: string[]
57+
): string {
58+
return fs.readFileSync(getFixturePath(projectRoot, segments), 'utf8');
59+
}
60+
61+
export async function compileAndroidMods(
62+
projectRoot: string,
63+
propsOverrides: Partial<JPushPluginProps> = {}
64+
): Promise<void> {
65+
const config = withJPush(
66+
createExpoConfig(),
67+
createPluginProps(propsOverrides)
68+
);
69+
70+
await compileModsAsync(config, {
71+
projectRoot,
72+
platforms: ['android'],
73+
});
74+
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
apply plugin: "com.android.application"
2+
apply plugin: "org.jetbrains.kotlin.android"
3+
apply plugin: "com.facebook.react"
4+
5+
def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()
6+
7+
/**
8+
* This is the configuration block to customize your React Native Android app.
9+
* By default you don't need to apply any configuration, just uncomment the lines you need.
10+
*/
11+
react {
12+
entryFile = file(["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android", "absolute"].execute(null, rootDir).text.trim())
13+
reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
14+
hermesCommand = new File(["node", "--print", "require.resolve('hermes-compiler/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/hermesc/%OS-BIN%/hermesc"
15+
codegenDir = new File(["node", "--print", "require.resolve('@react-native/codegen/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
16+
17+
enableBundleCompression = (findProperty('android.enableBundleCompression') ?: false).toBoolean()
18+
// Use Expo CLI to bundle the app, this ensures the Metro config
19+
// works correctly with Expo projects.
20+
cliFile = new File(["node", "--print", "require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })"].execute(null, rootDir).text.trim())
21+
bundleCommand = "export:embed"
22+
23+
/* Folders */
24+
// The root of your project, i.e. where "package.json" lives. Default is '../..'
25+
// root = file("../../")
26+
// The folder where the react-native NPM package is. Default is ../../node_modules/react-native
27+
// reactNativeDir = file("../../node_modules/react-native")
28+
// The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
29+
// codegenDir = file("../../node_modules/@react-native/codegen")
30+
31+
/* Variants */
32+
// The list of variants to that are debuggable. For those we're going to
33+
// skip the bundling of the JS bundle and the assets. By default is just 'debug'.
34+
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
35+
// debuggableVariants = ["liteDebug", "prodDebug"]
36+
37+
/* Bundling */
38+
// A list containing the node command and its flags. Default is just 'node'.
39+
// nodeExecutableAndArgs = ["node"]
40+
41+
//
42+
// The path to the CLI configuration file. Default is empty.
43+
// bundleConfig = file(../rn-cli.config.js)
44+
//
45+
// The name of the generated asset file containing your JS bundle
46+
// bundleAssetName = "MyApplication.android.bundle"
47+
//
48+
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
49+
// entryFile = file("../js/MyApplication.android.js")
50+
//
51+
// A list of extra flags to pass to the 'bundle' commands.
52+
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
53+
// extraPackagerArgs = []
54+
55+
/* Hermes Commands */
56+
// The hermes compiler command to run. By default it is 'hermesc'
57+
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
58+
//
59+
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
60+
// hermesFlags = ["-O", "-output-source-map"]
61+
62+
/* Autolinking */
63+
autolinkLibrariesWithApp()
64+
}
65+
66+
/**
67+
* Set this to true in release builds to optimize the app using [R8](https://developer.android.com/topic/performance/app-optimization/enable-app-optimization).
68+
*/
69+
def enableMinifyInReleaseBuilds = (findProperty('android.enableMinifyInReleaseBuilds') ?: false).toBoolean()
70+
71+
/**
72+
* The preferred build flavor of JavaScriptCore (JSC)
73+
*
74+
* For example, to use the international variant, you can use:
75+
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
76+
*
77+
* The international variant includes ICU i18n library and necessary data
78+
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
79+
* give correct results when using with locales other than en-US. Note that
80+
* this variant is about 6MiB larger per architecture than default.
81+
*/
82+
def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'
83+
84+
android {
85+
ndkVersion rootProject.ext.ndkVersion
86+
87+
buildToolsVersion rootProject.ext.buildToolsVersion
88+
compileSdk rootProject.ext.compileSdkVersion
89+
90+
namespace 'com.anonymous.mxjpushexpoandroid1aIhJx'
91+
defaultConfig {
92+
applicationId 'com.anonymous.mxjpushexpoandroid1aIhJx'
93+
minSdkVersion rootProject.ext.minSdkVersion
94+
targetSdkVersion rootProject.ext.targetSdkVersion
95+
versionCode 1
96+
versionName "1.0.0"
97+
98+
buildConfigField "String", "REACT_NATIVE_RELEASE_LEVEL", "\"${findProperty('reactNativeReleaseLevel') ?: 'stable'}\""
99+
}
100+
signingConfigs {
101+
debug {
102+
storeFile file('debug.keystore')
103+
storePassword 'android'
104+
keyAlias 'androiddebugkey'
105+
keyPassword 'android'
106+
}
107+
}
108+
buildTypes {
109+
debug {
110+
signingConfig signingConfigs.debug
111+
}
112+
release {
113+
// Caution! In production, you need to generate your own keystore file.
114+
// see https://reactnative.dev/docs/signed-apk-android.
115+
signingConfig signingConfigs.debug
116+
def enableShrinkResources = findProperty('android.enableShrinkResourcesInReleaseBuilds') ?: 'false'
117+
shrinkResources enableShrinkResources.toBoolean()
118+
minifyEnabled enableMinifyInReleaseBuilds
119+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
120+
def enablePngCrunchInRelease = findProperty('android.enablePngCrunchInReleaseBuilds') ?: 'true'
121+
crunchPngs enablePngCrunchInRelease.toBoolean()
122+
}
123+
}
124+
packagingOptions {
125+
jniLibs {
126+
def enableLegacyPackaging = findProperty('expo.useLegacyPackaging') ?: 'false'
127+
useLegacyPackaging enableLegacyPackaging.toBoolean()
128+
}
129+
}
130+
androidResources {
131+
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~'
132+
}
133+
}
134+
135+
// Apply static values from `gradle.properties` to the `android.packagingOptions`
136+
// Accepts values in comma delimited lists, example:
137+
// android.packagingOptions.pickFirsts=/LICENSE,**/picasa.ini
138+
["pickFirsts", "excludes", "merges", "doNotStrip"].each { prop ->
139+
// Split option: 'foo,bar' -> ['foo', 'bar']
140+
def options = (findProperty("android.packagingOptions.$prop") ?: "").split(",");
141+
// Trim all elements in place.
142+
for (i in 0..<options.size()) options[i] = options[i].trim();
143+
// `[] - ""` is essentially `[""].filter(Boolean)` removing all empty strings.
144+
options -= ""
145+
146+
if (options.length > 0) {
147+
println "android.packagingOptions.$prop += $options ($options.length)"
148+
// Ex: android.packagingOptions.pickFirsts += '**/SCCS/**'
149+
options.each {
150+
android.packagingOptions[prop] += it
151+
}
152+
}
153+
}
154+
155+
dependencies {
156+
// The version of react-native is set by the React Native Gradle Plugin
157+
implementation("com.facebook.react:react-android")
158+
159+
def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
160+
def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
161+
def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";
162+
163+
if (isGifEnabled) {
164+
// For animated gif support
165+
implementation("com.facebook.fresco:animated-gif:${expoLibs.versions.fresco.get()}")
166+
}
167+
168+
if (isWebpEnabled) {
169+
// For webp support
170+
implementation("com.facebook.fresco:webpsupport:${expoLibs.versions.fresco.get()}")
171+
if (isWebpAnimatedEnabled) {
172+
// Animated webp support
173+
implementation("com.facebook.fresco:animated-webp:${expoLibs.versions.fresco.get()}")
174+
}
175+
}
176+
177+
if (hermesEnabled.toBoolean()) {
178+
implementation("com.facebook.react:hermes-android")
179+
} else {
180+
implementation jscFlavor
181+
}
182+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
2+
<uses-permission android:name="android.permission.INTERNET"/>
3+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" tools:replace="android:maxSdkVersion"/>
4+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
5+
<uses-permission android:name="android.permission.VIBRATE"/>
6+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" tools:replace="android:maxSdkVersion"/>
7+
<queries>
8+
<intent>
9+
<action android:name="android.intent.action.VIEW"/>
10+
<category android:name="android.intent.category.BROWSABLE"/>
11+
<data android:scheme="https"/>
12+
</intent>
13+
</queries>
14+
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/AppTheme" android:supportsRtl="true" android:enableOnBackInvokedCallback="false">
15+
<meta-data android:name="expo.modules.updates.ENABLED" android:value="false"/>
16+
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
17+
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
18+
<activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode|smallestScreenSize" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN"/>
21+
<category android:name="android.intent.category.LAUNCHER"/>
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
</manifest>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
google()
6+
mavenCentral()
7+
}
8+
dependencies {
9+
classpath('com.android.tools.build:gradle')
10+
classpath('com.facebook.react:react-native-gradle-plugin')
11+
classpath('org.jetbrains.kotlin:kotlin-gradle-plugin')
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
google()
18+
mavenCentral()
19+
maven { url 'https://www.jitpack.io' }
20+
}
21+
}
22+
23+
apply plugin: "expo-root-project"
24+
apply plugin: "com.facebook.react.rootproject"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Project-wide Gradle settings.
2+
3+
# IDE (e.g. Android Studio) users:
4+
# Gradle settings configured through the IDE *will override*
5+
# any settings specified in this file.
6+
7+
# For more details on how to configure your build environment visit
8+
# http://www.gradle.org/docs/current/userguide/build_environment.html
9+
10+
# Specifies the JVM arguments used for the daemon process.
11+
# The setting is particularly useful for tweaking memory settings.
12+
# Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
13+
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
14+
15+
# When configured, Gradle will run in incubating parallel mode.
16+
# This option should only be used with decoupled projects. More details, visit
17+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18+
org.gradle.parallel=true
19+
20+
# AndroidX package structure to make it clearer which packages are bundled with the
21+
# Android operating system, and which are packaged with your app's APK
22+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
23+
android.useAndroidX=true
24+
25+
# Enable AAPT2 PNG crunching
26+
android.enablePngCrunchInReleaseBuilds=true
27+
28+
# Use this property to specify which architecture you want to build.
29+
# You can also override it from the CLI using
30+
# ./gradlew <task> -PreactNativeArchitectures=x86_64
31+
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
32+
33+
# Use this property to enable support to the new architecture.
34+
# This will allow you to use TurboModules and the Fabric render in
35+
# your application. You should enable this flag either if you want
36+
# to write custom TurboModules/Fabric components OR use libraries that
37+
# are providing them.
38+
newArchEnabled=true
39+
40+
# Use this property to enable or disable the Hermes JS engine.
41+
# If set to false, you will be using JSC instead.
42+
hermesEnabled=true
43+
44+
# Use this property to enable edge-to-edge display support.
45+
# This allows your app to draw behind system bars for an immersive UI.
46+
# Note: Only works with ReactActivity and should not be used with custom Activity.
47+
edgeToEdgeEnabled=true
48+
49+
# Enable GIF support in React Native images (~200 B increase)
50+
expo.gif.enabled=true
51+
# Enable webp support in React Native images (~85 KB increase)
52+
expo.webp.enabled=true
53+
# Enable animated webp support (~3.4 MB increase)
54+
# Disabled by default because iOS doesn't support animated webp
55+
expo.webp.animated=false
56+
57+
# Enable network inspector
58+
EX_DEV_CLIENT_NETWORK_INSPECTOR=true
59+
60+
# Use legacy packaging to compress native libraries in the resulting APK.
61+
expo.useLegacyPackaging=false

0 commit comments

Comments
 (0)