However, when building tests for your application, you want to assert that the right flow-tracking or error is being sent to Sentry, but without really sending it to Sentry servers. This way you won't swamp Sentry with false reports during test running and other CI operations.
Sentry Testkit - to the rescue
Sentry Testkit enables Sentry to work natively in your application, and by overriding the default Sentry transport mechanism, the report is not really sent but rather logged locally into memory. In this way, the logged reports can be fetched later for your own usage, verification, or any other use you may have in your local developing/testing environment.
npm install sentry-testkit --save-dev
Using in tests
const sentryTestkit =const testkit sentryTransport =const DUMMY_DSN = '';// initialize your Sentry instance with sentryTransportSentry// then run any scenario that should call Sentry.catchException(...)const report = testkit0
Network interception support
Instead of modifying your application code, you can use network interception libraries in conjunction with the testkit.
Example with nock:
const nock =const sentryTestkit =const testkit initNetworkInterceptor =
const sentryTestkit =const testkit =testkitpuppeteer;// Run any scenario that will call Sentry.captureException(...), for example:await page;const report = testKit0testkitpuppeteer;
You may see more usage examples in the testing section of this repository as well.
Test Kit API
See full API description and documentation here: https://wix.github.io/sentry-testkit/
What About Nodejs?
sentry-testkit have full support in both
@sentry/node since they have the same API and lifecycle under the hood.
The good old legacy
raven-testkit documentation can be found here. It it still there to serve