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

ddt

v0.1.0

Published

A Data Driven Test library for node.js

Downloads

6

Readme

ddt

A Data Driven Test library for node.js

build status

This module iterates a list of input test data and for each data creates a test case by transforming the data and validating the generated result with expected data in the output list.

API

Require the ddt module and call test method against a config object.

var ddt = require('ddt');
ddt.test(config);

save the file e.g. test.js and then execute the test with mocha

mocha test.js

config

  • inputs: an array of test case inputs.
  • outputs: an array of expected test results.
  • transform(input): a function for trasforming an input test case data, this is the function to be tested. Parameter input is the input test case data.
  • validate(expected, actual): a function for validating transformed data (from input) to expected value which is from outputs array.
  • groupName: a string value representing the group name for all the test cases. If the value is not specified, then all the test cases will be not grouped.
  • caseName: could be a string or a function. If it s string value, each test case will be nameed with it; if it is a function, the test case name will be generated from calling of it. The function accepts 3 parameters: index, inputs and outputs for helping generating name based on actual test case.

Example

Suppose have 6 test cases, each test case has an integer input number and the expected value is the double of the input number. So, the 6 input test cases are [1, 2, 3, 4, 5, 6] and the exptected outputs are [2, 4, 6, 8, 10, 12]

var ddt = require('ddt');
var config = {
    inputs: [1, 2, 3, 4, 5, 6],
    outputs: [2, 4, 6, 8, 10, 12],
    trasform: function(input) {
        return 2 * input;
    },
    validate: function(expected, actual) {
        return expected == actual;
    },
    groupName: 'Double of a number',
    caseName: function(index, inputs, outputs) {
        return 'Doubling of number ' + inputs[index] + ' should return ' + outputs[index];
    }
};

ddt.test(config);

Save the file as test.js then use mocha to run the tests

mocha test.js --reporter spec

The test result is:

 Double of a number
    ✓ Doubling of number 1 should return 2 
    ✓ Doubling of number 2 should return 4 
    ✓ Doubling of number 3 should return 6 
    ✓ Doubling of number 4 should return 8 
    ✓ Doubling of number 5 should return 10 
    ✓ Doubling of number 6 should return 12

Test

Make sure mocha is installed globally

npm install mocha -g

Run npm test to run unit test

License

MIT