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 🙏

© 2026 – Pkg Stats / Ryan Hefner

retap

v2.0.0

Published

Wrapper around tape that adds functions for testing React components

Readme

retap

Wrapper around tape that adds functions for testing React components.

Installation

npm install retap --save-dev

Overview

I wanted tests for generated markup that were thorough, and easy to read and maintain. Use t.isSameMarkup to compare a JSX representation of a component with a JSX representation of the elements you expect to see.

This module can return a react-unit component from t.createComponent.

Usage

Running tests

Since your tests probably include JSX, they need to be transpiled. I use babel-tape-runner:

npm install -g babel-tape-runner
babel-tape-runner tests/**/*.jsx

That gives raw tap output. You can pipe it to faucet to make it easier to read.

npm install -g faucet
babel-tape-runner tests/**/*.jsx | faucet

Rather than global installs, you can install babel-tape-runner and faucet as dev dependencies and run them with npm test:

// package.json
  ...
  "scripts": {
    "test": "babel-tape-runner tests/**/*.jsx | faucet"
  },
  "devDependencies": {
    "babel-tape-runner": "^1.2.0",
    "faucet": "0.0.1",
    "react": "^0.13.3"
  }
  ...

Writing tests

Use it like tape, but now you can call t.isSameMarkup() with JSX to compare. You don't have to use JSX - if you feel like using React.createElement(), who am I to stop you?

import test from 'retap'
// needed for compiled JSX in expected
import React from 'react'
import DwarfPlanet from '../components/DwarfPlanet'

test('DwarfPlanet generates correct markup', t => {
  const actual = (
    <DwarfPlanet designation="134340 Pluto"
      className="plutoid trans-neptunian-object kuiper-belt-object"
      satellites={['Charon', 'Styx', 'Nix', 'Kerberos', 'Hydra']}/>
  )

  const expected = (
    <div className="dwarf-planet plutoid trans-neptunian-object kuiper-belt-object">
      <h2>134340 Pluto</h2>
      <h3>Satellites</h3>
      <ul>
        <li className="moon">Charon</li>
        <li className="moon">Styx</li>
        <li className="moon">Nix</li>
        <li className="moon">Kerberos</li>
        <li className="moon">Hydra</li>
      </ul>
    </div>
  )

  t.isSameMarkup(actual, expected)

  // it is easier to use t.end() rather than try to figure out how many
  // comparisons isSameMarkup will do to use t.plan()
  t.end()
})

You can get a react-unit component with t.createComponent() to manually check props and other things (see react-unit). The component cannot be passed to isSameMarkup (I intend to fix that in future), so keep the JSX return value if you want to use both approaches:

import test from 'retap'
// needed for compiled JSX
import React from 'react'
import DwarfPlanet from '../components/DwarfPlanet'

test('DwarfPlanet generates correct markup', t => {
  const actual = (
    <DwarfPlanet designation="1 Ceres"
      satellites={[]}/>
  )

  const actualComponent = t.createComponent(actual)

  const heading = actualComponent.findByQuery('h2')
  t.equal(heading.props.value, '1 Ceres', 'Should show designation in H2')

  t.isSameMarkup(actual, (
    <div className="dwarf-planet">
      <h2>1 Ceres</h2>
      No known satellites
    </div>
  ))

  // it is easier to use t.end() rather than try to figure out how many
  // comparisons isSameMarkup will do to use t.plan()
  t.end()
})

API

t.isSameMarkup(actual, expected)

Generate tap errors in the output for mismatches between actual and expected. Not everything is checked, checks run are:

  • elements are of correct types and are in the same tree structure
  • classNames match (in any order)
  • styles match in any order
  • text content matches
  • title attribute matches
  • src matches (for tags)
  • href matches (for tags)
  • content set with dangerouslySetInnerHTML matches

*Note: isSameMarkup will perform numerous checks that each count as part of the test plan, so take these into account if using t.plan().

Params

Both must be React elements, which you can make with JSX or manually.

  • actual - the element under test, with test props
  • expected - the expected markup

e.g.

t.isSameMarkup(<MinorPlanet name="Eris"/>,
               <div className="minor-planet">Eris</div>)

t.createComponent(jsx)

Create a react-unit component. Basically a shortcut to the react-unit module. See react-unit

Params

  • jsx - React element, specified with JSX or manually.