zivl / sentry-testkit

A Sentry plugin to allow Sentry report interception and further inspection of the data being sent
https://zivl.github.io/sentry-testkit/
MIT License
112 stars 26 forks source link

`testkit.reset()` doesn't reset Sentry scope #50

Closed pptang closed 2 years ago

pptang commented 4 years ago

Summary

If Sentry.configureScope(...) is ever called and some scopes are being set (such as scope.setUser or scope.setTag, it cannot be reset, is it expected behaviour?

How to reproduce

describe('testkit.reset()', () => {
  it('does not reset Sentry scope', () => {
    Sentry.init({
      dsn: 'https://dummy@sentry.io/000001',
      transport: sentryTransport,
    });

    Sentry.configureScope(scope => {
      scope.setUser({ id: 'test-id' });
      scope.setTag('tagName', 'test-tag');
    });

    Sentry.captureException(new Error('first exception'));
    expect(testkit.reports()).toHaveLength(1);
    expect(testkit.reports()[0].tags).toMatchObject({ tagName: 'test-tag' });
    expect(testkit.reports()[0].user).toMatchObject({ id: 'test-id' });

    testkit.reset();
    expect(testkit.reports()).toHaveLength(0);

    Sentry.captureException(new Error('second exception'));
    // Expect to be empty, but it persists the previous scope values
    expect(testkit.reports()[0].tags).toBe({});
    expect(testkit.reports()[0].user).toBe(undefined);
  });
});
Screen Shot 2020-05-08 at 16 21 55
zivl commented 4 years ago

hey @pptang , sorry for the delay. can you specify your sentry/sentry-testkit versions?

github-actions[bot] commented 2 years ago

Stale issue message