-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(modules): Modules loaders integration handles native error and ev…
…ent modules are prioritised over native (#2730)
- Loading branch information
1 parent
4b32ab4
commit c35c86b
Showing
4 changed files
with
70 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Event, EventHint } from '@sentry/types'; | ||
|
||
import { ModulesLoader } from '../../src/js/integrations'; | ||
import { NATIVE } from '../../src/js/wrapper'; | ||
|
||
jest.mock('../../src/js/wrapper'); | ||
|
||
describe('Modules Loader', () => { | ||
let integration: ModulesLoader; | ||
|
||
beforeEach(() => { | ||
integration = new ModulesLoader(); | ||
}); | ||
|
||
it('integration event processor does not throw on native error', async () => { | ||
(NATIVE.fetchModules as jest.Mock).mockImplementation(() => { throw new Error('Test Error') }); | ||
const mockEvent: Event = { | ||
modules: { | ||
eventModule: 'eventModuleVersion', | ||
}, | ||
}; | ||
const processedEvent = await executeIntegrationFor(mockEvent); | ||
|
||
expect(processedEvent).toEqual(mockEvent); | ||
}); | ||
|
||
it('merges event modules with native modules', async () => { | ||
(NATIVE.fetchModules as jest.Mock).mockImplementation(() => ({ | ||
nativeModules: 'nativeModuleVersion', | ||
duplicateModule: 'duplicateNativeModuleVersion', | ||
})); | ||
const mockEvent: Event = { | ||
modules: { | ||
eventModule: 'eventModuleVersion', | ||
duplicateModule: 'duplicateEventModuleVersion', | ||
} | ||
}; | ||
const processedEvent = await executeIntegrationFor(mockEvent); | ||
|
||
expect(processedEvent?.modules).toEqual({ | ||
eventModule: 'eventModuleVersion', | ||
nativeModules: 'nativeModuleVersion', | ||
duplicateModule: 'duplicateEventModuleVersion', | ||
}); | ||
}); | ||
|
||
function executeIntegrationFor(mockedEvent: Event, mockedHint: EventHint = {}): Promise<Event | null> { | ||
return new Promise((resolve, reject) => { | ||
integration.setupOnce(async (eventProcessor) => { | ||
try { | ||
const processedEvent = await eventProcessor(mockedEvent, mockedHint); | ||
resolve(processedEvent); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
}); | ||
} | ||
}); |