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

sirrobert-test-vows

v1.3.7

Published

A more terse DSL around the Vows testing module.

Downloads

10

Readme

Rationale

This is a thin wrapper around vows. I didn't like how verbose vows is, but I like the async features.

Installation

Local installation

npm install --save sirrobert-test-vows

Global installation

npm install --global sirrobert-test-vows

Usage

Comparison with Vows

For a full description of vows, you should check out the vows website. Here's a brief comparison, though.

The vows site gives a brief example of testing some division by zero errors:

// division-by-zero-test.js

var vows = require('vows'),
    assert = require('assert');

// Create a Test Suite
vows.describe('Division by Zero').addBatch({
    'when dividing a number by zero': {
        topic: function () { return 42 / 0 },

        'we get Infinity': function (topic) {
            assert.equal (topic, Infinity);
        }
    },
    'but when dividing zero by zero': {
        topic: function () { return 0 / 0 },

        'we get a value which': {
            'is not a number': function (topic) {
                assert.isNaN (topic);
            },
            'is not equal to itself': function (topic) {
                assert.notEqual (topic, topic);
            }
        }
    }
}).run(); // Run it

Here's the same thing using this DSL. I've left the same comments so it doesn't get shorter for cheaty reasons.

// division-by-zero-test.js

var Test = require("sirrobert-test-vows");

// Create a Test Suite
new Test(
  "Division by Zero",
  { when: "dividing a number by zero",
    using: () => 42/0,
    "we get Infinity": result => Test.is.equal(result, Infinity)
  },
  { when: "dividing zero by zero",
    using: () => 0/0,
    "we get a value which": {
      "is not a number":        result => Test.it.isNaN(result),
      "is not equal to itself": result => Test.is.notEqual(result,result),
    }
  }
).run(module); // Run it

In my opinion, this is much more readable. Mainly because I don't relate to the "vows", "topic", "batch" language in vows, but also because it reads approximately like a sentence:

Test
  "blah blah"

    when "blah blah"
    using <some method>
    "result 1" <by this means>,
    "result 2" <by this means>,
    "result 3" <by this means>,

    when "blah blah"
    using <some method>
    "result 1" <by this means>,
    "result 2" <by this means>,
    "result 3" <by this means>,

Sugar

This module also smuggles in node's assert module so you don't have to import it yourself. You can, of course. There's some sugar to make it a little sweeter: you can write short sentences with the module for your assertions.

Test.is(...);
Test.is.equal(...);
Test.is.StrictEqual(...);
Test.it.doesNotThrow(...);
Test.does.fail(...);

all three objects (.is, .it, and .does) are just synonyms for the assert module. That means these are all exactly equivalent:

Test.is.equal(...);
Test.it.equal(...);
Test.does.equal(...);

... and so on for all other assert features.

How it Works

Dead simple, it just takes the data structure provided here and re-arranges it slightly to be the vows infrastructure. The source is a couple dozen lines, so reading that will probably be an easier way to understand it.