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

tapsy

v0.0.10

Published

testing framework

Downloads

6

Readme

Tapsy

Minimalistic Testing Runner With TAP Output

Tapsy makes it easy to convert a simple sequence of operations into a test-suite. The philosophy is:

  • TAP format so you can choose from the many reporter libraries out there.
  • There are no config-files or other extraneous stuff.
  • The library itself is simple enough that you can easily debug into it if you have to.
  • Just a few simple dependencies, so npm install is kept fast and no hidden complexity.
  • What you need and nothing more.

Tutorial

To get started you should import header and assert from Tapsy:

const { assert, header } = require('tapsy');

When you call header with a string, a TAP header will be produced - mainly for making the output easier to read by breaking it up into sections.

When you call assert, you should provide a string describing what you are testing and a function that does the testing operations. The assert-function should then be chained with one of three functions:

  • succeeds - use this to assert that the operation does not throw any exceptions
  • fails - use this to assert that the operation throws an exception
  • equals - use this to assert that the operation results in a value with a specific structure. Tapsy uses deep comparison so will work for objects too.

Simple Example

const { assert, header } = require('tapsy');

header('arithmetic');

assert('1 + 1 = 2', () => 1 + 1).equals(2);

function divide(a, b) {
  if (b === 0) throw 'division by zero is undefined';
  return a / b;
}

assert('10 / 5', () => divide(10, 5)).succeeds();
assert('division by 0', () => divide(10, 0)).fails();

If you run this with node you will get the TAP output:

TAP version 13
# arithmetic
ok 1 1 + 1 = 2
ok 2 10 / 5
ok 3 division by 0
1..3

Which can be piped to a reporter of your choice. For tap-difflet it looks like this:

Example output

Setup and Teardown

The succeeds, fails and equals functions all return a promise that will not resolve until the test operation is finished (also works for test operations that return a promise, Tapsy will wait for the promise to resolve). This means you can easily control the sequence of operations simply by using await to synchronize when needed:

async function test_db() {
  header('setup and teardown');

  const db = await connect_to_db();
  assert('create user', () => <...>).succeeds();
  assert('get user', () => <...>).equals(<user-object>);
  await assert('delete user', () => <...>).succeeds();

  db.disconnect();
}

test_db();

Notice that it is not necessary to wait for each assertion to finish to ensure the ordering of test operations, Tapsy will always run them in order. It is only necessary when you need to do your own operations after one or more tests.

Alternatively you can use the provided queue function that allows you put something on the internal Tapsy queue and be assured that things will happen in order:

const { assert, header, queue } = require('tapsy');

header('setup and teardown');

let db = null;
queue(async () => { db = await connect_to_db(); });
assert('create user', () => <...>).succeeds();
assert('get user', () => <...>).equals(<user-object>);
assert('delete user', () => <...>).succeeds();
queue(() => db.disconnect());