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

@swatk6/tester

v1.1.0

Published

A lightweight testing package using the assumptions (expected vs actual) model.

Downloads

2

Readme

swatk6-tester

A lightweight testing package using the assumptions (expected vs actual) model. The report can be displayed or retrieved as a special array.

It can check the following:

  • strict equality between the expected and actual item;
  • underflows (not enough tests were done; only possible if you use the pre-set expectation format);
  • overflows (more results that expected; only possible if you use the pre-set expectation format).

Caution: since it's possible to call matchResponses() and then carrying on adding more responses, the next matchResponses() call will carry on testing only the new values. Therefore if a test must pass the entire roster, make sure you quit at the first false return from matchResponses(). Also, it's possible to rewind() the test index, after which matchResponses() will test the entire suite from the start.

Usage

npm install --save @swatk6/tester

const tester = require('@swatk6/tester');

tester.addResponse(true,false,'should fail');
...
if (tester.matchResponses()===false) {
    process.exit(1);
} else {
    process.exit(0);
}

For a detailed example, see test.js in this package.

Reference

Methods

new tester()

Constructor.

addRequirement(expected[,label])

  • expected <*>: the result we expected from that operation; only strict equality will pass
  • label <String>: optional label, defaults to 'response #NN', where NN is the current index of the test items
  • returns an empty response slot ID that will have to be filled with addResponseValue()

addResponse(result[,expected[,label])

  • result <*>: the actual result we got from an operation
  • expected <*>: the result we expected from that operation; only strict equality will pass; optional, defaults to 'N/A'
  • label <String>: optional label, defaults to 'response #NN', where NN is the current index of the test items
  • returns the tester object itself, allowing for chaining

addResponseValue(result,slotID)

  • result <*>: the actual result we got from an operation
  • slotID <Number>: the slot where we need to store this response, received from an earler addRequirement() call
  • returns the tester object itself, allowing for chaining

blockSync(msecs)

  • msecs <Number>: how many milliseconds to block for
  • returns the tester object itself, allowing for chaining

Block execution of the current script. Great for testing timeouts. Exact millisecond precision is not guaranteed.

getReport()

  • returns an <Array> of <Object>s where each object have the following properties:
    • step: <Number|null> which step of the test is the message about (null for generic entries or overflows)
    • type: 'mismatch_missing'|'mismatch_value'|'mismatch_overflow'|'ok'|'result_errors'
    • expects:
      • 'mismatch_missing'|'mismatch_value'|'ok': the required value
      • 'mismatch_overflow': undefined
      • 'result_errors': 0
    • actual:
      • 'mismatch_missing'|'mismatch_value'|'ok': the value we got
      • 'mismatch_overflow': the overflowing values as an Array
      • 'result_errors': number of steps that failed
  • label: the label for this step, or 'overflow', 'success', or 'failure'

matchResponses(): <Boolean>

  • returns true if there were no errors in the test, or false if there were

This format requires you to specify the expected argument for each addResponse() call.

matchResponses(responseSet): <Boolean>

  • responseSet <Array>: an array of expected result values
  • returns true if there were no errors in the test, or false if there were

In this format you pre-set an array of expected values, and match your current responses to that set. This allows detection of underflows (ie. an exception occurred that left a lot of expected responses void) or overflows (more responses were received than desired).

reset()

  • returns the tester object itself, allowing for chaining

Resets the entire test object; allows for reuse of the object.

rewind()

  • returns the tester object itself, allowing for chaining

Rewinds the matchResponses() current test index, allowing for re-testing the entire response chain.

setQuiet(isQuiet)

  • isQuiet <Boolean>: if false, test results are console.logged, if true, the test suite works without console output
  • returns the tester object itself, allowing for chaining

Author

(c) 2018. Andras Kemeny, @subpardaemon