All Projects → wix → sentry-testkit

wix / sentry-testkit

Licence: MIT license
A Sentry plugin to allow Sentry report interception and further inspection of the data being sent

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sentry-testkit

bugsnag-vue
[DEPRECATED] This package now lives within the monorepo for our Universal JS notifier "@bugsnag/js" • https://github.com/bugsnag/bugsnag-js
Stars: ✭ 26 (-66.67%)
Mutual labels:  error-monitoring, error-handling, error-reporting
elmah.io
ELMAH error logger for sending errors to elmah.io.
Stars: ✭ 31 (-60.26%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Bugsnag Node
[DEPRECATED] Please upgrade to our Universal JS notifier "@bugsnag/js" • https://github.com/bugsnag/bugsnag-js
Stars: ✭ 48 (-38.46%)
Mutual labels:  error-monitoring, error-handling, error-reporting
react-error-guard
⚛️An overlay for displaying stack frames based on create-react-app/packages/react-error-overlay
Stars: ✭ 18 (-76.92%)
Mutual labels:  error-monitoring, error-handling, error-reporting
raygun4py
Python provider for Raygun
Stars: ✭ 18 (-76.92%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Bugsnag Laravel
Bugsnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
Stars: ✭ 746 (+856.41%)
Mutual labels:  error-monitoring, error-handling, error-reporting
TrackJS-Node
TrackJS Error Monitoring agent for NodeJS
Stars: ✭ 26 (-66.67%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Bugsnag Php
Bugsnag error monitoring and crash reporting tool for PHP apps
Stars: ✭ 475 (+508.97%)
Mutual labels:  error-monitoring, error-handling, error-reporting
raygun4android
Android crash reporting provider for Raygun
Stars: ✭ 19 (-75.64%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Bugsnag Cocoa
Bugsnag crash reporting for iOS, macOS and tvOS apps
Stars: ✭ 167 (+114.1%)
Mutual labels:  error-monitoring, error-handling, error-reporting
bugsnag-java
Bugsnag error reporting for Java.
Stars: ✭ 51 (-34.62%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Emperror
The Emperor takes care of all errors personally
Stars: ✭ 201 (+157.69%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Bugsnag Js
Javascript error handling tool for Bugsnag. Monitor and report JavaScript bugs & errors.
Stars: ✭ 625 (+701.28%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Bugsnag Android Ndk
DEPRECATED - this project now lives at bugsnag/bugsnag-android
Stars: ✭ 42 (-46.15%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Sentry Javascript
Official Sentry SDKs for JavaScript. We're hiring https://grnh.se/ca81c1701us
Stars: ✭ 6,012 (+7607.69%)
Mutual labels:  error-monitoring, sentry, raven
Raygun4net
Raygun provider for .NET
Stars: ✭ 107 (+37.18%)
Mutual labels:  error-monitoring, error-handling, error-reporting
bugsnag-wordpress
Bugsnag error monitoring for WordPress sites
Stars: ✭ 20 (-74.36%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Bugsnag React Native
Error monitoring and reporting tool for native exceptions and JS errors in React Native apps
Stars: ✭ 374 (+379.49%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Bugsnag Go
Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
Stars: ✭ 155 (+98.72%)
Mutual labels:  error-monitoring, error-handling, error-reporting
Exceptionless
Exceptionless server and jobs
Stars: ✭ 2,107 (+2601.28%)
Mutual labels:  error-monitoring, error-handling, error-reporting

sentry-teskit

npm version npm downloads Test sentry version 5 sentry version 6

Sentry is an open-source JavaScript SDK published by Sentry to enable error tracking that helps developers monitor and fix crashes in real time.
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.

Usage

Installation

npm install sentry-testkit --save-dev

Usage

// some.spec.js
const sentryTestkit = require('sentry-testkit')

const {testkit, sentryTransport} = sentryTestkit()

// initialize your Sentry instance with sentryTransport
Sentry.init({
    dsn: 'some_dummy_dsn',
    transport: sentryTransport,
    //... other configurations
})

test('something', function () {
  // run any scenario that eventually calls Sentry.captureException(...)
  expect(testkit.reports()).toHaveLength(1)
  const report = testkit.reports()[0]
  expect(report).toHaveProperty(...)
});

Working with Jest

We've added a new option to integrate sentry-testkit with jest's mocking mechanism. Detailed implementation can be seen here.

At the moment it is available only to @sentry/browser package but we will expand to more packages as we should figure out how to do it right for all Sentry's client packages.

If you're using Jest for testing, all you have to do in your spec.js file is to import the Jest mock.

// some.spec.js
import { testkit } from 'sentry-testkit/dist/jestMock';

test('something', function () {
    // click
    // clack
    // BOOM!
    expect(testkit.reports().length).toBeGreaterThan(0);
});

Make sure to put your import statement before all other imports.

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 = require('nock')
const sentryTestkit = require('sentry-testkit')
const { testkit, initNetworkInterceptor } = sentryTestkit()

beforeAll(() => {
    const myAppDSN = '<your DSN goes here>'
    initNetworkInterceptor(myAppDSN, (baseUrl, handleRequestBody) => {
      // This callback is where we init our interceptor.
      // The interceptor should intercept requests from `baseUrl` and pass the
      // request body (as json) to the `handleRequestBody` function.
      nock(baseUrl)
        .persist()
        .post(/.*/)
        .reply(200, (_, requestBody) => {
          handleRequestBody(requestBody)
        })
    })
})

test('findReport example', async function() {
    const err = new Error('error to look for')

    // Some faulty scenario that will report err

    const report = testkit.findReport(err)
    expect(report).toBeDefined()
})

Yes! We 💙 Puppeteer

const sentryTestkit = require('sentry-testkit')

const {testkit} = sentryTestkit()

testkit.puppeteer.startListening(page);

// Run any scenario that will call Sentry.captureException(...), for example:
await page.addScriptTag({ content: `throw new Error('An error');` });

expect(testKit.reports()).toHaveLength(1)
const report = testKit.reports()[0]
expect(report).toHaveProperty(...)

testkit.puppeteer.stopListening(page);

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?

Of Course! sentry-testkit have full support in both @sentry/browser and @sentry/node since they have the same API and lifecycle under the hood.

Raven-Testkit

The good old legacy raven-testkit documentation can be found here. It it still there to serve Raven which is the old legacy SDK of Sentry for JavaScript/Node.js platforms

Running in browser

sentry-testkit relies on express and http packages from NodeJS. We have separated entry sentry-testkit/browser where we not include any NodeJS-related code.

const sentryTestkit = require('sentry-testkit/browser');

const {testkit} = sentryTestkit()
// Your code for browser
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].