Skip to content

Commit 566550e

Browse files
committed
Extend test cases with realistic data
1 parent 9ae5475 commit 566550e

File tree

2 files changed

+177
-9
lines changed

2 files changed

+177
-9
lines changed

packages/core/test/expo-plugin/modifyAppDelegate.test.ts

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,74 @@ interface MockedExpoConfig extends ExpoConfig {
2121
};
2222
}
2323

24+
const objcContents = `#import "AppDelegate.h"
25+
26+
@implementation AppDelegate
27+
28+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
29+
{
30+
self.moduleName = @"main";
31+
32+
// You can add your custom initial props in the dictionary below.
33+
// They will be passed down to the ViewController used by React Native.
34+
self.initialProps = @{};
35+
36+
return [super application:application didFinishLaunchingWithOptions:launchOptions];
37+
}
38+
39+
@end
40+
`;
41+
42+
const objcExpected = `#import "AppDelegate.h"
43+
#import <RNSentry/RNSentry.h>
44+
45+
@implementation AppDelegate
46+
47+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
48+
{
49+
[RNSentrySDK start];
50+
self.moduleName = @"main";
51+
52+
// You can add your custom initial props in the dictionary below.
53+
// They will be passed down to the ViewController used by React Native.
54+
self.initialProps = @{};
55+
56+
return [super application:application didFinishLaunchingWithOptions:launchOptions];
57+
}
58+
59+
@end
60+
`;
61+
62+
const swiftContents = `import React
63+
import React_RCTAppDelegate
64+
import ReactAppDependencyProvider
65+
import UIKit
66+
67+
@main
68+
class AppDelegate: RCTAppDelegate {
69+
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
70+
self.moduleName = "sentry-react-native-sample"
71+
self.dependencyProvider = RCTAppDependencyProvider()
72+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
73+
}
74+
}`;
75+
76+
const swiftExpected = `import React
77+
import React_RCTAppDelegate
78+
import ReactAppDependencyProvider
79+
import UIKit
80+
import RNSentry
81+
82+
@main
83+
class AppDelegate: RCTAppDelegate {
84+
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
85+
RNSentrySDK.start()
86+
self.moduleName = "sentry-react-native-sample"
87+
self.dependencyProvider = RCTAppDependencyProvider()
88+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
89+
}
90+
}`;
91+
2492
describe('modifyAppDelegate', () => {
2593
let config: MockedExpoConfig;
2694

@@ -32,8 +100,7 @@ describe('modifyAppDelegate', () => {
32100
slug: 'test',
33101
modResults: {
34102
path: 'samples/react-native/ios/AppDelegate.swift',
35-
contents:
36-
'import UIKit\n\noverride func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {',
103+
contents: swiftContents,
37104
language: 'swift',
38105
},
39106
};
@@ -71,19 +138,20 @@ describe('modifyAppDelegate', () => {
71138
it('should modify a Swift file by adding the RNSentrySDK import and start', async () => {
72139
const result = (await modifyAppDelegate(config)) as MockedExpoConfig;
73140

74-
expect(result.modResults.contents).toContain('import RNSentrySDK');
141+
expect(result.modResults.contents).toContain('import RNSentry');
75142
expect(result.modResults.contents).toContain('RNSentrySDK.start()');
143+
expect(result.modResults.contents).toBe(swiftExpected);
76144
});
77145

78146
it('should modify an Objective-C file by adding the RNSentrySDK import and start', async () => {
79147
config.modResults.language = 'objc';
80-
config.modResults.contents =
81-
'#import "AppDelegate.h"\n\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {';
148+
config.modResults.contents = objcContents;
82149

83150
const result = (await modifyAppDelegate(config)) as MockedExpoConfig;
84151

85152
expect(result.modResults.contents).toContain('#import <RNSentry/RNSentry.h>');
86153
expect(result.modResults.contents).toContain('[RNSentrySDK start];');
154+
expect(result.modResults.contents).toBe(objcExpected);
87155
});
88156

89157
it('should insert import statements only once in an Swift project', async () => {

packages/core/test/expo-plugin/modifyMainApplication.test.ts

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
24122
describe('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

Comments
 (0)