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 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-unit-test

v1.3.3

Published

Providing convenient methods to do fitering to the variables.

Downloads

34

Readme

node-unit-test

Lightweight library for doing unit-test on NodeJs

What's new

v1.3.1

  • Fix bug: Could not run multiple testcases testing

v1.3.0

  • Display result in color

v1.2.0

  • Add data provider
  • Fix bug of the execute method to return the test result as true/false value

v1.1.0

  • Add assert method 'assertError'
  • Add assert method 'assertNotError'

Install

npm install node-unit-test

Usage

TestSuite

var TestSuite = require('node-unit-test');
var testSuite = new TestSuite();

var result = testSuite
.addFile('/path/to/test/file/testcase_1.js')
.addFile('/path/to/test/file/testcase_2.js')
.execute();

process.exit(result ? 0 : 1);

TestCase

Example of testcase file:

module.exports = function(){

  return {
    test_something: (assert)=>{
      // Code here
    },
    test_another: (assert)=>{
      // Code here
    }
  };
};

Data provider

Data provider function is the function that have same name with the test function, begin with the prefix 'data'.

module.exports = function(){

  return {
    // This is data provider for the test_something
    data_something: ()=>{
      return [
        // mixed Data item 1,
        // mixed Data item 2,
        // ...
      ];
    },
    test_something: (assert, dataItem)=>{
      // Do something with given dataItem
    }
  };
};

Assert

fail

assert.fail(message)

assert

assert.assert(expected, actual, message)

assertEquals

assert.assertEquals(expected, actual, message)

assertNotEquals

assert.assertNotEquals(expected, actual, message)

assertSame

assert.assertSame(expected, actual, message)

assertNotSame

assert.assertNotSame(expected, actual, message)

assertUndefined

assert.assertUndefined(actual, message)

assertNotUndefined

assert.assertNotUndefined(actual, message)

assertNull

assert.assertNull(actual, message)

assertNotNull

assert.assertNotNull(actual, message)

assertTrue

assert.assertTrue(actual, message)

assertFalse

assert.assertFalse(actual, message)

assertTypeof

assert.assertTypeof(expected, actual, message)

assertNotTypeOf

assert.assertNotTypeof(expected, actual, message)

assertRequired

assert.assertRequired(actual, message)

assertEmpty

assert.assertEmpty(actual, message)

assertInstanceof

assert.assertInstanceof(expected, actual, message)

assertClassName

assert.assertClassName(expected, actual, message)

assertError

assert.assertError(callback, message)

assertNotError

assert.assertNotError(callback, message)

Result

Run test './test-node-unit-test.js'
==============================================
[ ✘ ] Test test_fail
[ ✘ ] Test test_assert
[ ✘ ] Test test_assert_equals
[ ✘ ] Test test_assert_not_equals
[ ✘ ] Test test_assert_same
[ ✘ ] Test test_assert_not_same
[ ✘ ] Test test_assert_undefined
[ ✘ ] Test test_assert_not_undefined
[ ✘ ] Test test_assert_null
[ ✘ ] Test test_assert_not_null
[ ✘ ] Test test_assert_true
[ ✘ ] Test test_assert_false
[ ✘ ] Test test_assert_typeof
[ ✘ ] Test test_assert_not_typeof
[ ✘ ] Test test_assert_required
[ ✘ ] Test test_assert_empty
[ ✘ ] Test test_assert_instanceof
[ ✘ ] Test test_assert_class_name
[ ✘ ] Test test_assert_error
[ ✘ ] Test test_assert_not_error
[ ✘ ] Test test_assert_data_provider_one
[ ✔ ] Test test_assert_data_provider_many [data # 0]
[ ✘ ] Test test_assert_data_provider_many [data # 1]
[ ✘ ] Test test_system_error_1
[ ✘ ] Test test_system_error_2 [data # 0]
[ ✘ ] Test test_system_error_2 [data # 1]
[ ✔ ] Test test_ok
----------------------------------------------
● test_fail:
    Assert Error: This is fail

● test_assert:
    Assert Error: This is error (expected: 'expected', actual: 'actual')

● test_assert_equals:
    Assert Error: Not equals (expected: 1, actual: '1')

● test_assert_not_equals:
    Assert Error: Equals (expected: NOT 1, actual: 1)

● test_assert_same:
    Assert Error: Not same (expected: 1, actual: 2)

● test_assert_not_same:
    Assert Error: Same (expected: NOT 1, actual: '1')

● test_assert_undefined:
    Assert Error: Not undefined (expected: UNDEFINED, actual: NULL)

● test_assert_not_undefined:
    Assert Error: Undefined (expected: NOT UNDEFINED, actual: UNDEFINED)

● test_assert_null:
    Assert Error: Not null (expected: NULL, actual: UNDEFINED)

● test_assert_not_null:
    Assert Error: Null (expected: NOT NULL, actual: NULL)

● test_assert_true:
    Assert Error: False (expected: TRUE, actual: FALSE)

● test_assert_false:
    Assert Error: True (expected: FALSE, actual: TRUE)

● test_assert_typeof:
    Assert Error: Not string (expected: 'string', actual: 'number')

● test_assert_not_typeof:
    Assert Error: String (expected: NOT 'string', actual: 'string')

● test_assert_required:
    Assert Error: Empty (expected: REQUIRED, actual: EMPTY STRING)

● test_assert_empty:
    Assert Error: Not empty (expected: EMPTY, actual: 123)

● test_assert_instanceof:
    Assert Error: Not array (expected: 'Array', actual: 'Number')

● test_assert_class_name:
    Assert Error: Object (expected: 'Object', actual: 'Array')

● test_assert_error:
    Assert Error: Not error (expected: ERROR, actual: NOT ERROR)

● test_assert_not_error:
    Assert Error: Error (expected: NOT ERROR, actual: ERROR (Error: This is error))

● test_assert_data_provider_one:
    Assert Error: Must be "Hello world" (expected: 'Hello world', actual: 'Hello')

● test_assert_data_provider_many [data # 1]:
    Assert Error: This is error (expected: '123', actual: '321')

● test_system_error_1:
    Error: This is system error 1

● test_system_error_2 [data # 0]:
    Error: This is system error 2

● test_system_error_2 [data # 1]:
    Error: This is system error 2

==============================================
Result: FAILED (Testcase: 25, Failed: 25, Assert: 41, Error: 22)

License

ISC