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

ks_unit_test_esm

v1.0.1

Published

A minimalist JS unit testing tool, Follow the ES Module specification

Readme

JS Unit Test tool - UnitTest

If you want a lightweight JavaScript unit test plug-in. Then use UnitTest directly to unit test your JavaSript code. Rest assured that UnitTest Core is only the size of 3KB, so you don't have to worry about the impact of the introduction of UnitTest on the performance of your project.

The project follows the ESM specification, and the UnitTest CMJ project can be seen:

Install

npm install -d ks_unitTest_esm

File directory

  • main.js - Project entry file

Usage

1. Import

import { unitTestSet } from 'ks_unitTest_esm'


unitTestSet(fun, tsetList, resultList, debug);

2. Use UnitTest

To use UnitTest to help you implement unit tests, you need to provide something:

  • testFun:The function you want to test
  • testList:Test case parameter list
  • resultList:List of test expected results
  • debug:Whether to enable detailed error stack information of failed test cases. Default is false.

Test Data

// This is the test function.
const add = function (a, b) {
    return a + b;
}

// This is its list of test parameters, and it should be in the form of a two-dimensional array
//  [
//     [param1, param2 ...],		// Test case one
//     [param1, param2 ...],		// Test case two
//     [param1, param2 ...],		// Test case three
//  ]
const testList = [
    [1, 2],
    [2, 3],
    [0, 1]
];

// This is a list of its predictive trial results. 
// It should be in the form of an one-dimensional array. 
// The exact type of expected result depends on your own function return value format.
//  [
//     Expected to return result one,
//     Expected to return result two,
//     Expected to return result three
//  ]
const resultList = [
    3,
    5,
    2
];

const debug = false;

unitTestSet(add, testList, resultList, false);

Sample output

示例输出一

3. Get information about failed unit test cases

Assuming that the given condition is the same as in 2. Use UnitTest, you only need to name a variable to accept the return value of the unitTestSet function.

const failTestList = unitTestSet(add, testList, resultList, false);
console.log(failTestList);

Sample output

示例输出二

4. Self-test

Of course, a good unit test can test whether it is normal or not, and of course, because self-testing can lead to meaningless callbacks, the first selfTestList.roomth test results are the real unit test cases for self-testing.

Test Data

const testList = [
    [1, 2],
    [2, 3],
    [0, 1]
];

const resultList = [
    3,
    5,
    2
];

const selfTestList = [
    [unitTest, testList, resultList, false]
]

const selfResultList = [
    undefined
]

console.log('\n开始自我测试:');
unitTestSet(unitTestSet, selfTestList, selfResultList, false);

Sample output

示例输出三