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

zopf

v7.0.0

Published

tape + sinon + promises + sourcemaps = zopf

Downloads

42

Readme

zopf

MIT licensed Build Status js-standard-style Dependency Status

If you're running a bunch of tests:

  • Transpiled from another languages (ES2015 to ES5 via babel, for example) and for which you'd like stack traces in the original language
  • That use sinon to spy, stub and mock things
  • That sometimes return promises
  • That should fail individually when they throw

...and you want to avoid setting all that up yourself for every test case or file, then zopf just might be for you.

Usage & examples

zopf is actually a thin wrapper over tape, which means you can use it pretty much the same:

var test = require('zopf')

test('basic test', function (t) {
  t.is(true, true)
})

You don't need to call t.end().

If you return a Promise, the test will be async and will pass if no assertion fail and the promise resolves.

If you return something else, the test will end there.

The context, t, is augmented with a sinon sandbox that lets you create spies, stubs and mocks, and verifies all of them at the end of the test.

import test from 'zopf'
import Promise from 'bluebird'

let foo = {
  bar: () => Promise.resolve('Uh oh.')
}

test('using promises', t => {
  let mock = t.mock(foo)
  mock.expects('bar').returns(Promise.resolve('Success!'))

  return foo.bar().then(res => {
    t.is(res, 'Success!')
  })
})

In that last example:

  • If foo.bar() rejects, the test will fail
  • If foo.bar() resolves without calling our mock, the test will fail when the sinon sandbox is verified
  • If foo.bar() resolves, our mock has been called, but the return value is wrong, the test will fail

Running tests

Simply use tape to run your zopf tests - as long as you require('zopf') instead of require('tape') you'll get all the zopf niceties for free.

The best way is probably to run npm install --save-dev tape and add an npm script to your package.json:

{
  "name": "yourpackage",
  "scripts": {
    "test": "tape spec/*-test.js"
  }
}

Name meaning / pronunciation

Zopf is a type of Swiss bread, which basically means braid. It seemed appropriate for this module as it braids together several test facilities and was short and available on npm.

License

Licensed under MIT License, see LICENSE for details.