Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sentry-testkit

zivl486.2kMIT6.2.2TypeScript support: included

Sentry Testkit enables Sentry to work natively in your application while running tests. The report is not really sent but rather logged locally into memory. In this way, the logged reports can be fetched for your own verification or any other purpose in y

raven-test-kit, raven, sentry, sentry-io, raven-js, raven-node, sentry-testkit, error-reporting, error-monitoring, sentry-error-handler, sentry-plugin, sentry-client

readme

npm version npm downloads Test

sentry version 8 sentry version 9

sentry-testkit

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.

Installation

npm:

npm install sentry-testkit --save-dev

yarn:

yarn add sentry-testkit --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('collect error events', function () {
  // run any scenario that eventually calls Sentry.captureException(...)
  expect(testkit.reports()).toHaveLength(1)
  const report = testkit.reports()[0]
  expect(report).toHaveProperty(...)
});

// Similarly for performance events
test('collect performance events', function () {
  // run any scenario that eventually calls Sentry.startTransaction(...)
  expect(testkit.transactions()).toHaveLength(1)
});

Testkit API

See full API description and documentation here: https://zivl.github.io/sentry-testkit/

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

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

Change Log

We're constantly and automatically updating our CHANGELOG file, so its always a good spot to checkout what have we been up to...

Contribution

We'd love any kind of contribution, to get better, improve our capabilities, fix bugs and bring more features as Sentry expanding their tools as well. Please check our CONTRIBUTING guidelines for more info and how to get started.

License

Sentry Testkit is MIT licensed.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

6.2.2 (2025-05-06)

6.2.1 (2025-05-06)

Bug Fixes

  • handle event type in createTestkit to push reports correctly to address Puppeteer events (a550064), closes #193

6.2.0 (2025-04-27)

Features

  • initialize expo-react-native-test-app with essential configurations (#234) (40c0b07)

6.1.0 (2025-03-06)

Please take a look at the migration guide for version 6 to check out latest additions and breaking changes.

BREAKING CHANGES:

  • change support for nodejs versions #222

    Features

  • adding support for sentry@8 and sentry@9 packages for node, react and browser #224, closes #200

  • ci: add multiple sentry versions and testing environments #221
  • chore: add spanId and parentSpanId #223 closes #216
  • bump major version to 6.0.0 (a2e62f2)

Docs

  • docs: upgrade docs engine and add migration guide from 5-to-6 #225

5.1.0 (2025-03-06)

Features

  • adding support for sentry@8 and sentry@9 packages for node, react and browser (65a9191), closes #200

5.0.10 (2025-02-26)

5.0.9 (2024-03-01)

5.0.8 (2023-11-21)

Bug Fixes

5.0.7 (2023-11-13)

5.0.6 (2023-09-23)

5.0.5 (2023-01-04)

Bug Fixes

  • local server not capturing error events from the browser (#152) (6e43809)
  • support all content types in local server endpoints (#153) (063a538)
  • support all content types in local server endpoints (#161) (d5d0685)

5.0.4 (2022-12-04)

Bug Fixes

  • default export when importing in pure node ESM (#145) (42aa0cc)

5.0.3 (2022-10-21)

Bug Fixes

  • SentryTransport factory function return "any" until TS issue will be fixed (#141) (a1d07ca), closes #138

5.0.2 (2022-10-21)

Bug Fixes

5.0.1 (2022-10-21)

Bug Fixes

5.0.0 (2022-10-20)

⚠ BREAKING CHANGES

  • move case base to typescript (#137)

  • move case base to typescript (#137) (0c45d14), closes #114

4.1.0 (2022-09-30)

Features

4.0.3 (2022-08-03)

Bug Fixes

4.0.2 (2022-07-28)

Bug Fixes

  • types: Update to support new V7 transport style (#116) (ebdb751)

4.0.1 (2022-07-07)

4.0.0 (2022-07-07)

Features

3.3.8 (2022-06-29)

3.3.7 (2021-10-27)

3.3.6 (2021-10-18)

3.3.5 (2021-10-13)

Bug Fixes

  • items other than transform sent in an envelope request cause an error (#89)

3.3.4 (2021-06-20)

Bug Fixes

3.3.3 (2021-06-18)

3.3.2 (2021-02-22)

3.3.0 (2021-02-04)

Features

  • add ready-to-use jest mock with testkit builtin (80e602c)

3.2.4 (2021-01-29)

3.2.3 (2021-01-29)