Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions packages/node/test/onunhandledrejection.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import { Hub, init, Integrations, Scope } from '../src';
import { Scope } from '@sentry/core';
import { Hub } from '@sentry/hub';
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my learning -- Does changing this import affect the test, or is it just cosmetic/preference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosmetic preference


const dsn = 'https://[email protected]/4291';
import { OnUnhandledRejection } from '../src/integrations/onunhandledrejection';

jest.mock('@sentry/hub', () => {
// we just want to short-circuit it, so dont worry about types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the rest of the change, don't fully understand this.

Why do we want to short-circuit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because setupOnce is checking whether an integration is installed, which in the case of these tests should always be the case. I think this was the reason for flakyness, because hub is attached to the global object.

const original = jest.requireActual('@sentry/hub');
original.Hub.prototype.getIntegration = () => true;
return {
...original,
getCurrentHub: () => new Hub(),
};
});

describe('unhandled promises', () => {
test('install global listener', () => {
init({ dsn });
const integration = new OnUnhandledRejection();
integration.setupOnce();
expect(process.listeners('unhandledRejection')).toHaveLength(1);
});

test('sendUnhandledPromise', () => {
const integration = new Integrations.OnUnhandledRejection();
const integration = new OnUnhandledRejection();
integration.setupOnce();

const promise = {
domain: {
sentryContext: {
Expand Down