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

danger-testing

v1.0.1

Published

Easy to use testing of DangerJS/dangerfile

Downloads

1

Readme

Danger JS Testing

About this project

This project was created to allow a developer to test their DangerJS dangerfile through Jest unit testing. It also works with testing imported DangerJS plugins.

Getting started

:warning: This project is currently going through ramp up development.
Some things may change, some things may not work. Submit issues if you find any.

This package requires a minimum Danger and Jest version to function but it may function with future and previous versions as well. Create an issue/discussion if you test a version outside the required versions that you have found that works.

Installation

Until published install via direct GitHub link

$ npm install danger-testing --save-dev

This project assumes that Danger and Jest are already installed in your project.

Usage

Move dangerfile checks into a function or separate functions if you haven't done so previously.

// dangerfileFunctions.ts

// break your checks into functions that are exported.
// 📢 optionally, put all the functions inside a bigger function 
// that's exported to test closer to how Danger would report.
export const checkLineAdditions = () => {
  if (danger.github.pr.additions > 500) {
    warn('PR exceeds number of lines added')
  }
}

Create a test file like dangerfile.spec.ts to write your tests.

// dangerfile.spec.ts
import { dangerTesting, warn } from 'danger-js-testing'
import { checkLineAdditions } from '../dangerfile'

it('should call warn function if PR additions exceed 500 lines of code', async() => {
  await dangerTesting(checkLineAdditions, {
    github: {
      pr: {
        additions: 900,
      },
    },
  })

  expect(warn).toHaveBeenCalledWith(
    'PR exceeds number of lines added'
  )
  expect(warn).toHaveBeenCalledTimes(1)
})

How it works

Takes inspiration from the documentation on the Danger website and myself wanting to have an easy way to test Danger during development.

The dangerTesting function accepts two arguments. One is the dangerfile function you have written for your tests. The second is the mock override we attach to the global danger object.

When dangerTesting is called it updates the global mock and then calls the passed in function.

This module exports danger like global mock functions like fail, markdown, message, and warn, to allow you to check that they are called as expected.