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 🙏

© 2026 – Pkg Stats / Ryan Hefner

clean-tests

v0.0.2

Published

A lightweight pure ECMAScript test library with a programmatic API for any ECMAScript/TypeScript environment

Readme

clean-tests ✅️

NPM version dependencies: none minzipped size code style: prettier Conventional Commits License MIT

A lightweight, zero-overhead ECMAScript test library with a programmatic API for any ECMAScript/TypeScript environment.

We create a suite of tests as a regular instance of the Suite class, fill it with tests using the suite.addTest method, possibly export it, and run it using the suite.run method.

The tests are run in the same thread as the suite.run call, but in an isolated scope, meaning that variables from the closure will not be available in the tests. To access the utilities, asserts, and functions being tested in the suite, we explicitly add them as functions to the suite scope using the suite.addFunctionToScope method.

A test is considered to have failed if it throws an exception (or if the promise it returns is rejected — for example, for asynchronous functions).

Basic example

import {assertValueIsTrue, Suite} from 'clean-tests';
import {sum} from './sum.js';

const suite = new Suite();

suite.addFunctionToScope(assertValueIsTrue);
suite.addFunctionToScope(sum);

suite.addTest('adds 1 + 2 to equal 3', () => {
  assertValueIsTrue(sum(1, 2) === 3);
});

const runResult = await suite.run();

assertValueIsTrue(runResult.runStatus === 'passed');

Features

Skipping tests

You can skip a specific test by giving it the skip option:

suite.addTest('skipped', {skip: true}, () => {
  // this code will never run
});

suite.addTest('skipped with reason', {skip: 'some reason''}, () => {
  // this code will never run
});

todo tests

The test can be marked as a todo test — in this case it will be run, but will not affect the runStatus:

suite.addTest('todo test', {todo: true}, () => {
  // some code
});

suite.addTest('todo test with reason', {todo: 'some reason''}, () => {
  // some code
});

only tests

The test can be marked as an only test — in this case, only only tests (there may be several of them) will be run, regardless of filtering of tests:

suite.addTest('only test', {only: true}, () => {
  // some code
});

fail tests

The test can be marked as a fail test — in this case the test will be considered passed if it throws (or rejects the returned promise), and failed otherwise:

suite.addTest('fail test', {fail: true}, () => {
  throw new Error('should throws');
});

Filtering of tests

Tests in suite.run can be filtered using the filterTests function (filtering is ignored if there is at least one only test in the suite):

suite.addTest('foo', () => {
  // some code
});

suite.addTest('bar', () => {
  // some code
});

// will run only the test named 'foo'
const runResult = await suite.run({filterTests: (_options, test) => test.name === 'foo'});

The default filter of tests can be set when creating a suite (the filter specified in suite.run will override it):

// run only tests with retries (i.e. tests that will be rerun if they fail)
const suite = new Suite({filterTests: (_options, test) => test.retries > 0});

Asynchronous tests

If a test returns a promise (usually as asynchronous function), clean-tests ✅️ waits for it to be fulfilled. Such a test is considered to have failed if the promise is rejected:

suite.addTest('asynchronous test', async () => {
  await new Promise((resolve) => setTimeout(resolve, 1_000));
});

For asynchronous tests you can specify a timeout in milliseconds, after which they will be considered failed:

suite.addTest('asynchronous test', {timeout: 1_000}, async () => {
  await new Promise((resolve) => setTimeout(resolve, 2_000));
});

The default timeout for each test can be set when creating the suite (the timeout specified in suite.run will override it):

const suite = new Suite({testTimeout: 3_000});

By default testTimeout is 10_000 (10 seconds).

For asynchronous tests, you can specify concurrency (how many of them can be run at the same time at most):

const runResult = await suite.run({concurrency: 3});

The default concurrency can be set when creating a suite (the concurrency specified in suite.run will override it):

const suite = new Suite({concurrency: 3});

By default concurrency is 1.

Install

Works in any environment that implements the ECMAScript 2022 standard (or higher): modern browser, node (version 16 or higher), Deno, Bun.

npm install --save-dev clean-tests

License

MIT