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

Package detail

raven-testkit

wix192MIT1.3.19

Raven test kit module to enable reports to sentry in tests without really sending the report

raven, testkit, test kit, raven test kit, raven test, sentry, sentry.io, sentry test kit

readme

npm version GitHub Hackage-Deps

Raven is a JavaScript SDK published by Sentry.io to enable software flow tracking and issues reporting to the Sentry system.
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 the Sentry system. This way you won't swamp it with false reports during test running and other CI operations.

Raven Test Kit - to the rescue

Raven test kit enables Raven to work natively in your application, but it overrides the default Raven transport mechanism so the report is not really sent but rather logged locally. In this way, the logged reports can be fetched later for usage verification or other uses you may have in your testing environment.

Usage

Installation

npm install raven-testkit --save-dev

Instantiation

// CommonJS
const testKitInitializer = require('raven-testkit')

// ES6 Modules
import testKitInitializer from 'raven-testkit'

Using in tests

const testKit = testKitInitializer(Raven)

// any scenario that should call Raven.catchException(...)

expect(testKit.reports()).toHaveLength(1)
const report = testKit.reports()[0]
expect(report).toHaveProperty('release', 'test')

Pass your own shouldSendCallback logic

const shouldSendCallback = data => {
    return /* your own logic */
}
const testKit = testKitInitializer(Raven, shouldSendCallback)

You may see more example usage in the testing section of this repository as well.

Test Kit API

reports() : Array

Get all existing reports.

Kind: instance function Returns: Array - where each member of the array consists of Raven's data object. See: You may refer to the Sentry Docs for further explanation and details.

reset() : Array

Reset the teskit state and clear all existing reports.

Returns: Array - empty array.

extractException(report) : Object

Extract the exception object of a given report.

Returns: Object - the exception object as built by Raven

Param Type Description
report Object report object.

getExceptionAt(index) : Object

Extract the exception object of a report in a specific position.

Returns: Object - the exception object as built by Raven

Param Type Description
index number index position of the report

findReport(error) : Object | undefined

Find a report by a given error.

Returns: Object | undefined - the report object if one found. undefined otherwise See: Uses Array.prototype.find

Param Type Description
error Error error to look for in the reports

isExist(error) : Boolean

check whether a given error exist (i.e. has been reported)

Returns: Boolean - true if the error exists. false otherwise

Param Type Description
error Error the error to look for in the reports

Gotcha(s)

  • if you set the shouldSendCallback hook in your Raven configuration, make sure to call the testKitInitializer(Raven) function after your code has finished configuring Raven. You need to do this because we call Raven.setShouldSendCallback to ensure the proper functionality of the Raven lifecycle so you need to call the testKitInitializer(Raven) only after Raven is configured.
    See the documentation above if you want to pass your own shouldSendCallback logic to raven-testkit.
  • Configure Raven to allow duplicates as otherwise the same dummy error will only be reported once. Raven.config(dummyDsn, { allowDuplicates: true }) (Documentation)

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)