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

iotest

v1.1.9

Published

test input/output

Downloads

8

Readme

NPM Version

iotest

Javascript library which makes input/output testing a no-brainer.

install

npm install --save-dev iotest

example with mocha

function f(x){
  return x + 1;
}

Test cases are processed sequentially when testing multiple cases:

const iotest = require('iotest');

describe('f', () => {
  it('should pass i/o tests', (done) => {

    const cases = [
      {inputs: 41, return: 42},
      {inputs: 0, return: 1}
    ];

    iotest(cases, f).
    then(outputs => {
      console.log(outputs):
      // => [42, 1]
      done();
    }).
    reject(done);

  });
});

Testing one case:

const iotest = require('iotest');

describe('f', () => {
  it('should pass i/o tests', (done) => {

    const case = { inputs: 41, return: 42 };

    iotest(case, f).
    then(outputs => {
      console.log(outputs):
      // => [42]
      done();
    }).
    reject(done);

  });
});

case

JSON object describing a test case.

case.inputs

Given arguments of a function.

single input

function f(x){
  return x + 1;
}
const iotest = require('iotest');

const cases = [
  { inputs: 41, return: 42 },    // succeed
  { inputs: [41], return: 42 },  // succeed
];      

iotest(cases, f).
then(outputs => { /* tests succeed */ }).
catch(err => { /* tests failed */ });

multiple inputs

function f(x, y){
  return x + y;
}
const iotest = require('iotest');

const case = { inputs: [10, 32], return: 42} // succeed    

iotest(case, f).
then(outputs => { /* tests succeed */ }).
catch(err => { /* tests failed */ });

case.return / case.error

Expected returned output of a function / Expected error thrown by a function.

function f(x, y){
  if(y === 0){
    throw new Error("division by 0");
  }
  return x / y;  
}
const iotest = require('iotest');

const cases = [
  { inputs: [42, 0], error: {} },   // succeed
  { inputs: [42, 2], return: 21 },  // succeed
];   

iotest(cases, f).
then(outputs => { /* tests succeed */ }).
catch(err => { /* tests failed */ });

case.resolve / case.reject

Expected resolved value / Expected rejected error, of the promise returned by a function.

function f(x, y){
  return new Promise( (resolve, reject) => {
    if(y === 0){
      reject(new Error("division by 0"));
    }else{
      resolve(x / y);  
    }
  });
}
const iotest = require('iotest');

const cases = [
  { inputs: [42, 0], reject: {} },   // succeed
  { inputs: [42, 2], resolve: 21 },  // succeed
];   

iotest(cases, f).
then(outputs => { /* tests succeed */ }).
catch(err => { /* tests failed */ });

depth traversal

if case.return, case.error, case.resolve or case.reject is set with an Object, then it is deeply traversed to make sure each property exists with the right value in the output.

function f(x){
  return {
    x: x,
    y: x + 1
  };
}
const iotest = require('iotest');

const cases = [
  { inputs: 41, return: {x: 41} },              // succeed
  { inputs: 0, return: {y: 1} },                // succeed
  { inputs: 1000, return: {x: 1000, y: 1001} }, // succeed
  { inputs: 7, return: {} }                     // succeed
];

iotest(cases, f).
then(outputs => { /* tests succeed */ }).
catch(err => { /* tests failed */ });

if case.return, case.error, case.resolve or case.reject is set with an Array, then each item is deeply traversed.

function f(x){
  return [
    { x: x, y: x + 1 },
    { x: x, y: y - 1 }
  ];
}
const iotest = require('iotest');

const case = {
  inputs: 41,
  return: [
    {x: 41, y: 42},
    {y: 40}
  ]
}; // succeed


iotest(case, f).
then(outputs => { /* tests succeed */ }).
catch(err => { /* tests failed */ });