-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MOB-10128] Increase JavaScript Test Coverage (#799)
* Test the `Trace` model * Test native `IBGAPM.startExecutionTrace` returns ID * Test uncovered `BugReporting` code * Test uncovered `NetworkLogger` code * Test uncovered `Instabug` code * Increase `APM` branch test coverage * Increase `Surveys` branch test coverage * Increase `Replies` branch test coverage * Increase `Instabug` branch test coverage * Test `Interceptor` stringifies request header values * Test `getActiveRoute` util * Test `getFullRoute` and `setOnReportHandler` util * Fix `xhr2` warning about GET request body * Increase `InstabugUtils` test coverage * Increase `XhrNetworkInterceptor` test coverage * Update test module CI Node version to 16.17 * Increase coverage target to 90%
- Loading branch information
Showing
15 changed files
with
632 additions
and
29 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
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ coverage: | |
status: | ||
patch: | ||
default: | ||
target: 75% | ||
target: 90% | ||
project: | ||
default: | ||
target: 75% | ||
target: 90% |
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
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
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,20 @@ | ||
jest.mock('react-native/Libraries/Core/Devtools/parseErrorStack', () => { | ||
const { Platform } = jest.requireActual('react-native'); | ||
|
||
// This mock's goal is to provide a parseErrorStack function that adapts to the mock React Native version | ||
// This mock should work as long as the tests run with React Native version < 0.64 | ||
return jest.fn(error => { | ||
const originalParseErrorStack = jest.requireActual( | ||
'react-native/Libraries/Core/Devtools/parseErrorStack', | ||
); | ||
|
||
if (!Platform.hasOwnProperty('constants') || Platform.constants.reactNativeVersion.minor < 64) { | ||
return originalParseErrorStack(error); | ||
} | ||
|
||
const wrapperError = new Error(); | ||
wrapperError.stack = error; | ||
|
||
return originalParseErrorStack(wrapperError); | ||
}); | ||
}); |
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,41 @@ | ||
import { NativeModules } from 'react-native'; | ||
import Trace from '../../src/models/Trace'; | ||
|
||
const { IBGAPM: NativeAPM } = NativeModules; | ||
|
||
describe('Trace Model', () => { | ||
it('should set the id, name and attributes if passed', () => { | ||
const id = 'trace-id'; | ||
const name = 'my-trace'; | ||
const attributes = { screen: 'login' }; | ||
const trace = new Trace(id, name, attributes); | ||
|
||
expect(trace.id).toBe(id); | ||
expect(trace.name).toBe(name); | ||
expect(trace.attributes).toBe(attributes); | ||
}); | ||
|
||
it('should set execution trace attributes', () => { | ||
const attribute = { key: 'isAuthenticated', value: true }; | ||
|
||
const trace = new Trace('trace-id'); | ||
trace.setAttribute(attribute.key, attribute.value); | ||
|
||
expect(trace.attributes[attribute.key]).toBe(attribute.value); | ||
expect(NativeAPM.setExecutionTraceAttribute).toBeCalledTimes(1); | ||
expect(NativeAPM.setExecutionTraceAttribute).toBeCalledWith( | ||
trace.id, | ||
attribute.key, | ||
attribute.value, | ||
); | ||
}); | ||
|
||
it('should end execution trace', () => { | ||
const trace = new Trace('trace-id'); | ||
|
||
trace.end(); | ||
|
||
expect(NativeAPM.endExecutionTrace).toBeCalledTimes(1); | ||
expect(NativeAPM.endExecutionTrace).toBeCalledWith(trace.id); | ||
}); | ||
}); |
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
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
Oops, something went wrong.