npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

raven-testkit

v1.3.19

Published

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

Downloads

139

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)