@@ -21,6 +21,104 @@ interface MockedExpoConfig extends ExpoConfig {
2121 } ;
2222}
2323
24+ const kotlinContents = `package io.sentry.expo.sample
25+
26+ import android.app.Application
27+
28+ import com.facebook.react.ReactApplication
29+ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
30+ import com.facebook.react.defaults.DefaultReactNativeHost
31+ import com.facebook.react.soloader.OpenSourceMergedSoMapping
32+ import com.facebook.soloader.SoLoader
33+
34+ import expo.modules.ApplicationLifecycleDispatcher
35+
36+ class MainApplication : Application(), ReactApplication {
37+ override fun onCreate() {
38+ super.onCreate()
39+ SoLoader.init(this, OpenSourceMergedSoMapping)
40+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
41+ // If you opted-in for the New Architecture, we load the native entry point for this app.
42+ load()
43+ }
44+ ApplicationLifecycleDispatcher.onApplicationCreate(this)
45+ }
46+ }
47+ ` ;
48+
49+ const kotlinExpected = `package io.sentry.expo.sample
50+
51+ import io.sentry.react.RNSentrySDK
52+ import android.app.Application
53+
54+ import com.facebook.react.ReactApplication
55+ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
56+ import com.facebook.react.defaults.DefaultReactNativeHost
57+ import com.facebook.react.soloader.OpenSourceMergedSoMapping
58+ import com.facebook.soloader.SoLoader
59+
60+ import expo.modules.ApplicationLifecycleDispatcher
61+
62+ class MainApplication : Application(), ReactApplication {
63+ override fun onCreate() {
64+ super.onCreate()
65+
66+ RNSentrySDK.init(this)
67+ SoLoader.init(this, OpenSourceMergedSoMapping)
68+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
69+ // If you opted-in for the New Architecture, we load the native entry point for this app.
70+ load()
71+ }
72+ ApplicationLifecycleDispatcher.onApplicationCreate(this)
73+ }
74+ }
75+ ` ;
76+
77+ const javaContents = `package com.testappplain;
78+
79+ import android.app.Application;
80+ import com.facebook.react.ReactApplication;
81+ import com.facebook.react.ReactInstanceManager;
82+ import com.facebook.react.ReactNativeHost;
83+ import com.facebook.react.config.ReactFeatureFlags;
84+ import com.facebook.soloader.SoLoader;
85+
86+ public class MainApplication extends Application implements ReactApplication {
87+ @Override
88+ public void onCreate() {
89+ super.onCreate();
90+ // If you opted-in for the New Architecture, we enable the TurboModule system
91+ ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
92+ SoLoader.init(this, /* native exopackage */ false);
93+ initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
94+ }
95+ }
96+ ` ;
97+
98+ const javaExpected = `package com.testappplain;
99+
100+ import io.sentry.react.RNSentrySDK;
101+ import android.app.Application;
102+ import com.facebook.react.ReactApplication;
103+ import com.facebook.react.ReactInstanceManager;
104+ import com.facebook.react.ReactNativeHost;
105+ import com.facebook.react.config.ReactFeatureFlags;
106+ import com.facebook.soloader.SoLoader;
107+
108+ public class MainApplication extends Application implements ReactApplication {
109+ @Override
110+ public void onCreate() {
111+ super.onCreate();
112+
113+ RNSentrySDK.init(this);
114+ // If you opted-in for the New Architecture, we enable the TurboModule system
115+ ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
116+ SoLoader.init(this, /* native exopackage */ false);
117+ initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
118+ }
119+ }
120+ ` ;
121+
24122describe ( 'modifyMainApplication' , ( ) => {
25123 let config : MockedExpoConfig ;
26124
@@ -32,7 +130,7 @@ describe('modifyMainApplication', () => {
32130 slug : 'test' ,
33131 modResults : {
34132 path : '/android/app/src/main/java/com/example/MainApplication.java' ,
35- contents : 'package com.example;\nsuper.onCreate();' ,
133+ contents : javaContents ,
36134 language : 'java' ,
37135 } ,
38136 } ;
@@ -60,17 +158,19 @@ describe('modifyMainApplication', () => {
60158 const result = ( await modifyMainApplication ( config ) ) as MockedExpoConfig ;
61159
62160 expect ( result . modResults . contents ) . toContain ( 'import io.sentry.react.RNSentrySDK;' ) ;
63- expect ( result . modResults . contents ) . toContain ( 'super.onCreate();\nRNSentrySDK.init(this);' ) ;
161+ expect ( result . modResults . contents ) . toContain ( 'RNSentrySDK.init(this);' ) ;
162+ expect ( result . modResults . contents ) . toBe ( javaExpected ) ;
64163 } ) ;
65164
66165 it ( 'should modify a Kotlin file by adding the RNSentrySDK import and init' , async ( ) => {
67166 config . modResults . language = 'kotlin' ;
68- config . modResults . contents = 'package com.example\nsuper.onCreate()' ;
167+ config . modResults . contents = kotlinContents ;
69168
70169 const result = ( await modifyMainApplication ( config ) ) as MockedExpoConfig ;
71170
72171 expect ( result . modResults . contents ) . toContain ( 'import io.sentry.react.RNSentrySDK' ) ;
73- expect ( result . modResults . contents ) . toContain ( 'super.onCreate()\nRNSentrySDK.init(this)' ) ;
172+ expect ( result . modResults . contents ) . toContain ( 'RNSentrySDK.init(this)' ) ;
173+ expect ( result . modResults . contents ) . toBe ( kotlinExpected ) ;
74174 } ) ;
75175
76176 it ( 'should insert import statements only once' , async ( ) => {
0 commit comments