-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump Android SDK & Set Native/Android SDK Name on crashes (#406)
* bump android & add native package name * fix ios code * change changelog * add tests for sdkinfo * Update android/src/main/java/io/sentry/capacitor/SentryCapacitor.java * Apply suggestions from code review Co-authored-by: Kryštof Woldřich <[email protected]> * add missing cap ref * fix tst * requested changes --------- Co-authored-by: Kryštof Woldřich <[email protected]>
- Loading branch information
1 parent
a7b5e2f
commit dffdcb8
Showing
7 changed files
with
150 additions
and
30 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
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const SDK_PACKAGE_NAME = 'npm:@sentry/capacitor'; | ||
export const SDK_NAME = 'sentry.javascript.capacitor'; | ||
export const SDK_VERSION = '0.12.1'; |
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,88 @@ | ||
import type { Event, EventHint, Package } from '@sentry/types'; | ||
|
||
import { SDK_NAME, SDK_VERSION } from '../../src/'; | ||
import { SdkInfo } from '../../src/integrations'; | ||
import { NATIVE } from '../../src/wrapper'; | ||
|
||
let mockedFetchNativeSdkInfo: jest.Mock<PromiseLike<Package | null>, []>; | ||
|
||
const mockPackage = { | ||
name: 'sentry-cocoa', | ||
version: '0.0.1', | ||
}; | ||
|
||
jest.mock('../../src/wrapper', () => { | ||
const actual = jest.requireActual('../../src/wrapper'); | ||
|
||
return { | ||
NATIVE: { | ||
...actual.NATIVE, | ||
platform: 'ios', | ||
fetchNativeSdkInfo: () => mockedFetchNativeSdkInfo(), | ||
}, | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
NATIVE.platform = 'ios'; | ||
}); | ||
|
||
describe('Sdk Info', () => { | ||
it('Adds native package and javascript platform to event on iOS', async () => { | ||
mockedFetchNativeSdkInfo = jest.fn().mockResolvedValue(mockPackage); | ||
const mockEvent: Event = {}; | ||
const processedEvent = await executeIntegrationFor(mockEvent); | ||
|
||
expect(processedEvent?.sdk?.packages).toEqual(expect.arrayContaining([mockPackage])); | ||
expect(processedEvent?.platform === 'javascript'); | ||
expect(mockedFetchNativeSdkInfo).toBeCalledTimes(1); | ||
}); | ||
|
||
it('Adds javascript platform but not native package on Android', async () => { | ||
NATIVE.platform = 'android'; | ||
mockedFetchNativeSdkInfo = jest.fn().mockResolvedValue(mockPackage); | ||
const mockEvent: Event = {}; | ||
const processedEvent = await executeIntegrationFor(mockEvent); | ||
|
||
expect(processedEvent?.sdk?.packages).toEqual(expect.not.arrayContaining([mockPackage])); | ||
expect(processedEvent?.platform === 'javascript'); | ||
expect(mockedFetchNativeSdkInfo).not.toBeCalled(); | ||
}); | ||
|
||
it('Does not overwrite existing sdk name and version', async () => { | ||
mockedFetchNativeSdkInfo = jest.fn().mockResolvedValue(null); | ||
const mockEvent: Event = { | ||
sdk: { | ||
name: 'test-sdk', | ||
version: '1.0.0', | ||
}, | ||
}; | ||
const processedEvent = await executeIntegrationFor(mockEvent); | ||
|
||
expect(processedEvent?.sdk?.name).toEqual('test-sdk'); | ||
expect(processedEvent?.sdk?.version).toEqual('1.0.0'); | ||
}); | ||
|
||
it('Does use default sdk name and version', async () => { | ||
mockedFetchNativeSdkInfo = jest.fn().mockResolvedValue(null); | ||
const mockEvent: Event = {}; | ||
const processedEvent = await executeIntegrationFor(mockEvent); | ||
|
||
expect(processedEvent?.sdk?.name).toEqual(SDK_NAME); | ||
expect(processedEvent?.sdk?.version).toEqual(SDK_VERSION); | ||
}); | ||
}); | ||
|
||
function executeIntegrationFor(mockedEvent: Event, mockedHint: EventHint = {}): Promise<Event | null> { | ||
const integration = new SdkInfo(); | ||
return new Promise((resolve, reject) => { | ||
integration.setupOnce(async eventProcessor => { | ||
try { | ||
const processedEvent = await eventProcessor(mockedEvent, mockedHint); | ||
resolve(processedEvent); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
}); | ||
} |