-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(node): Sets mechanism handled to false when it is a crash #3493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { Hub } from '@sentry/hub'; | ||
|
|
||
| import { OnUncaughtException } from '../src/integrations/onuncaughtexception'; | ||
|
|
||
| jest.mock('@sentry/hub', () => { | ||
| // we just want to short-circuit it, so dont worry about types | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is copy-pasted from somewhere else. This would be more useful if it explained why we do what we do and how it is relevant for the tests. |
||
| const original = jest.requireActual('@sentry/hub'); | ||
| original.Hub.prototype.getIntegration = () => true; | ||
| return { | ||
| ...original, | ||
| getCurrentHub: () => new Hub(), | ||
| }; | ||
| }); | ||
|
|
||
| describe('uncaught exceptions', () => { | ||
| test('install global listener', () => { | ||
| const integration = new OnUncaughtException(); | ||
| integration.setupOnce(); | ||
| expect(process.listeners('uncaughtException')).toHaveLength(1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We miss here comparing the steady state. If there was already a listener registered by any other means than calling If we want to test that the integration sets up an event listener, then we should compare the before-after. const before = process.listeners('uncaughtException').length;
...
integration.setupOnce();
const after = process.listeners('uncaughtException').length;
expect(after - before).toBe(1); |
||
| }); | ||
|
|
||
| test('sendUncaughtException', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could document better what's the intent of this test. One can see what it does, not why it does, what behavior is important and why is it important. I'm guessing the intention is to check that Inspiration: https://hynek.me/articles/document-your-tests/ |
||
| const integration = new OnUncaughtException({ onFatalError: jest.fn() }); | ||
| integration.setupOnce(); | ||
|
|
||
| const captureException = jest.spyOn(Hub.prototype, 'captureException'); | ||
|
|
||
| integration.handler({ message: 'message', name: 'name' }); | ||
|
|
||
| expect(captureException.mock.calls[0][1]?.data).toEqual({ | ||
| mechanism: { handled: false, type: 'onuncaughtexception' }, | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"on" is the JS way of saying it is registering an event handler... shouldn't this be simply "uncaught exception"?
https://develop.sentry.dev/sdk/event-payloads/exception/#exception-mechanism says "promise" as an example... that might be too short. A fix there might be in order too.