Skip to content

Commit 38e0bda

Browse files
author
Ali Abdelfattah
authored
Merge branch 'release/10.11.0' into fix/ios-build-variables-INSD-6153
2 parents 33c07a8 + dc040df commit 38e0bda

File tree

112 files changed

+16644
-6080
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+16644
-6080
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ workflows:
223223
context: cross-platform
224224
- test_module
225225
- test_sample
226-
# - test_android
226+
- test_android
227227
- test_ios
228228
- e2e_ios
229229
# - e2e_android
File renamed without changes.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## master
22

3+
* Adds APM.endAppLaunch API
34
* Fixes an issue with iOS sourcemap upload that causes the build to fail
45

56
## 10.9.1 (2021-10-13)

Dangerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ if github.pr_body.length < 3 && git.lines_of_code > 10
88
end
99

1010
if !git.modified_files.include?("CHANGELOG.md") && !declared_trivial
11-
fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](https://github.com/Instabug/Instabug-Flutter/blob/master/CHANGELOG.md).", sticky: false)
11+
warn("You have not included a CHANGELOG entry! \nYou can find it at [CHANGELOG.md](https://github.com/Instabug/Instabug-Flutter/blob/master/CHANGELOG.md).", sticky: false)
1212
end

InstabugSample/ios/InstabugSampleTests/InstabugAPMTests.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ - (void) testSetAppLaunchEnabled {
7777
OCMVerify([mock setAppLaunchEnabled:isEnabled]);
7878
}
7979

80+
- (void) testEndAppLaunch {
81+
id mock = OCMClassMock([IBGAPM class]);
82+
83+
OCMStub([mock endAppLaunch]);
84+
[self.instabugBridge endAppLaunch];
85+
OCMVerify([mock endAppLaunch]);
86+
}
87+
8088
- (void) testSetAutoUITraceEnabled {
8189
id mock = OCMClassMock([IBGAPM class]);
8290
BOOL isEnabled = YES;

InstabugSample/metro.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ module.exports = {
1414
},
1515
}),
1616
},
17+
maxWorkers: 2,
1718
};

__tests__/apm.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe("APM Module", () => {
2121
const endExecutionTrace = sinon.spy(NativeModules.IBGAPM, "endExecutionTrace");
2222
const startUITrace = sinon.spy(NativeModules.IBGAPM, "startUITrace");
2323
const endUITrace = sinon.spy(NativeModules.IBGAPM, "endUITrace");
24+
const endAppLaunch = sinon.spy(NativeModules.IBGAPM, "endAppLaunch");
2425

2526
beforeEach(() => {
2627
IBGEventEmitter.removeAllListeners();
@@ -38,6 +39,12 @@ describe("APM Module", () => {
3839
expect(setAppLaunchEnabled.calledOnceWithExactly(true)).toBe(true);
3940
});
4041

42+
it("should call the native method endAppLaunch", () => {
43+
APM.endAppLaunch();
44+
45+
expect(endAppLaunch.calledOnceWithExactly()).toBe(true);
46+
});
47+
4148
it("should call the native method setAutoUITraceEnabled", () => {
4249
APM.setAutoUITraceEnabled(true);
4350

android/build.gradle

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ android {
2929
dependencies {
3030
implementation 'com.android.support:multidex:1.0.3'
3131
implementation 'com.facebook.react:react-native:+'
32-
api('com.instabug.library:instabug:10.9.1') {
32+
api('com.instabug.library:instabug:10.11.0') {
3333
exclude group: 'com.android.support:appcompat-v7'
3434
}
35-
testImplementation 'org.mockito:mockito-core:1.10.19'
36-
testImplementation 'junit:junit:4.12'
37-
testImplementation 'org.powermock:powermock-api-mockito:1.6.6'
38-
testImplementation 'org.powermock:powermock-module-junit4-rule-agent:1.6.2'
39-
testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.6'
40-
testImplementation 'org.powermock:powermock-module-junit4:1.6.6'
35+
testImplementation "org.mockito:mockito-inline:3.4.0"
36+
testImplementation "org.mockito:mockito-android:3.4.0"
37+
testImplementation 'junit:junit:4.13.2'
38+
4139
}
4240

4341

android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ public void run() {
107107
});
108108
}
109109

110+
/**
111+
* Ends app launch
112+
*/
113+
@ReactMethod
114+
public void endAppLaunch() {
115+
MainThreadHandler.runOnMainThread(new Runnable() {
116+
@Override
117+
public void run() {
118+
try {
119+
APM.endAppLaunch();
120+
} catch (Exception e) {
121+
e.printStackTrace();
122+
}
123+
}
124+
});
125+
}
126+
110127
/**
111128
* Enables or disables auto UI tracing
112129
* @param isEnabled boolean indicating enabled or disabled.
Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,128 @@
11
package com.instabug.reactlibrary;
2-
3-
import android.os.Handler;
42
import android.os.Looper;
5-
import android.os.SystemClock;
63

74
import com.facebook.react.bridge.Callback;
85
import com.instabug.apm.APM;
9-
import com.instabug.apm.model.ExecutionTrace;
106

11-
import com.facebook.react.bridge.Arguments;
12-
import com.instabug.reactlibrary.utils.InstabugUtil;
137
import com.instabug.reactlibrary.utils.MainThreadHandler;
148

15-
import org.json.JSONArray;
9+
import org.junit.After;
1610
import org.junit.Before;
1711
import org.junit.Test;
18-
import org.junit.runner.RunWith;
19-
import org.mockito.Matchers;
20-
import org.mockito.internal.verification.VerificationModeFactory;
12+
import org.mockito.MockedStatic;
2113
import org.mockito.invocation.InvocationOnMock;
2214
import org.mockito.stubbing.Answer;
23-
import org.powermock.api.mockito.PowerMockito;
24-
import org.powermock.core.classloader.annotations.PrepareForTest;
25-
import org.powermock.modules.junit4.PowerMockRunner;
2615

2716
import java.util.concurrent.Executors;
2817
import java.util.concurrent.ScheduledExecutorService;
2918

30-
import static org.mockito.Matchers.any;
31-
import static org.mockito.Matchers.anyLong;
32-
import static org.mockito.Matchers.eq;
19+
import static org.mockito.ArgumentMatchers.any;
20+
import static org.mockito.Mockito.doAnswer;
21+
import static org.mockito.Mockito.mock;
22+
import static org.mockito.Mockito.mockStatic;
23+
import static org.mockito.Mockito.times;
3324
import static org.mockito.Mockito.verify;
34-
import static org.powermock.api.mockito.PowerMockito.doAnswer;
35-
import static org.powermock.api.mockito.PowerMockito.mock;
36-
import static org.powermock.api.mockito.PowerMockito.when;
37-
38-
@RunWith(PowerMockRunner.class)
39-
@PrepareForTest({Looper.class, android.os.Handler.class, APM.class, ExecutionTrace.class, SystemClock.class, Runnable.class, RNInstabugAPMModule.class, Arguments.class, InstabugUtil.class, MainThreadHandler.class})
25+
import static org.mockito.Mockito.when;
4026

4127
public class RNInstabugAPMModuleTest {
4228

4329
private RNInstabugAPMModule apmModule = new RNInstabugAPMModule(null);
44-
4530
private final static ScheduledExecutorService mainThread = Executors.newSingleThreadScheduledExecutor();
4631

32+
// Mock Objects
33+
private MockedStatic<Looper> mockLooper;
34+
private MockedStatic <MainThreadHandler> mockMainThreadHandler;
35+
private MockedStatic <APM> mockAPM;
36+
4737
@Before
4838
public void mockMainThreadHandler() throws Exception {
49-
PowerMockito.mockStatic(Looper.class);
39+
// Mock static functions
40+
mockAPM = mockStatic(APM.class);
41+
mockLooper = mockStatic(Looper.class);
42+
mockMainThreadHandler = mockStatic(MainThreadHandler.class);
43+
44+
// Mock Looper class
5045
Looper mockMainThreadLooper = mock(Looper.class);
5146
when(Looper.getMainLooper()).thenReturn(mockMainThreadLooper);
52-
Handler mockMainThreadHandler = mock(Handler.class);
47+
48+
// Override runOnMainThread
5349
Answer<Boolean> handlerPostAnswer = new Answer<Boolean>() {
5450
@Override
5551
public Boolean answer(InvocationOnMock invocation) throws Throwable {
56-
invocation.getArgumentAt(0, Runnable.class).run();
52+
invocation.getArgument(0, Runnable.class).run();
5753
return true;
5854
}
5955
};
60-
doAnswer(handlerPostAnswer).when(mockMainThreadHandler).post(any(Runnable.class));
61-
doAnswer(handlerPostAnswer).when(mockMainThreadHandler).postDelayed(any(Runnable.class), anyLong());
62-
PowerMockito.whenNew(Handler.class).withArguments(mockMainThreadLooper).thenReturn(mockMainThreadHandler);
56+
doAnswer(handlerPostAnswer).when(MainThreadHandler.class);
57+
MainThreadHandler.runOnMainThread(any(Runnable.class));
58+
}
59+
@After
60+
public void tearDown() {
61+
// Remove static mocks
62+
mockLooper.close();
63+
mockMainThreadHandler.close();
64+
mockAPM.close();
6365
}
6466

6567
/********APM*********/
6668

6769
@Test
68-
public void givenFalse$setEnabled_whenQuery_thenShouldCallNativeApiWithDisabled() {
69-
// given
70-
PowerMockito.mockStatic(APM.class);
70+
public void givenFalsesetEnabled_whenQuery_thenShouldCallNativeApiWithDisabled() {
7171
// when
7272
apmModule.setEnabled(false);
7373
// then
74-
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
74+
verify(APM.class, times(1));
7575
APM.setEnabled(false);
7676
}
7777

7878
@Test
79-
public void givenTrue$setEnabled_whenQuery_thenShouldCallNativeApiWithEnabled() {
80-
// given
81-
PowerMockito.mockStatic(APM.class);
79+
public void givenTruesetEnabled_whenQuery_thenShouldCallNativeApiWithEnabled() {
8280
// when
8381
apmModule.setEnabled(true);
8482
// then
85-
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
83+
verify(APM.class, times(1));
8684
APM.setEnabled(true);
8785
}
8886

8987
@Test
9088
public void givenFalse$setAppLaunchEnabled_whenQuery_thenShouldCallNativeApiWithDisabled() {
91-
// given
92-
PowerMockito.mockStatic(APM.class);
89+
9390
// when
9491
apmModule.setAppLaunchEnabled(false);
9592
// then
96-
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
93+
verify(APM.class, times(1));
9794
APM.setAppLaunchEnabled(false);
9895
}
9996

10097
@Test
10198
public void givenTrue$setAppLaunchEnabled_whenQuery_thenShouldCallNativeApiWithEnabled() {
102-
// given
103-
PowerMockito.mockStatic(APM.class);
99+
104100
// when
105101
apmModule.setAppLaunchEnabled(true);
106102
// then
107-
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
103+
verify(APM.class, times(1));
108104
APM.setAppLaunchEnabled(true);
109105
}
110106

111107
@Test
112-
public void givenString$startExecutionTrace_whenQuery_thenShouldCallNativeApi() {
108+
public void given$endAppLaunch_whenQuery_thenShouldCallNativeApiWithEnabled() {
113109
// given
114110
PowerMockito.mockStatic(APM.class);
111+
// when
112+
apmModule.endAppLaunch();
113+
// then
114+
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
115+
APM.endAppLaunch();
116+
}
117+
118+
@Test
119+
public void givenString$startExecutionTrace_whenQuery_thenShouldCallNativeApi() {
120+
115121
Callback callback = mock(Callback.class);
116122
// when
117123
apmModule.startExecutionTrace("trace", "1", callback);
118124
// then
119-
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
125+
verify(APM.class, times(1));
120126
APM.startExecutionTrace("trace");
121127
verify(callback).invoke(any());
122128
}
@@ -151,24 +157,22 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
151157

152158
@Test
153159
public void givenString$startUITrace_whenQuery_thenShouldCallNativeApiWithEnabled() {
154-
// given
155-
PowerMockito.mockStatic(APM.class);
160+
156161
// when
157162
apmModule.startUITrace("uiTrace");
158163
// then
159-
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
164+
verify(APM.class, times(1));
160165
APM.startUITrace("uiTrace");
161166
}
162167

163168
@Test
164169
public void given$endUITrace_whenQuery_thenShouldCallNativeApiWithEnabled() {
165-
// given
166-
PowerMockito.mockStatic(APM.class);
170+
167171
// when
168172
apmModule.startUITrace("uiTrace");
169173
apmModule.endUITrace();
170174
// then
171-
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
175+
verify(APM.class, times(1));
172176
APM.endUITrace();
173177
}
174178
}

0 commit comments

Comments
 (0)