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

@mizchi/testio

v0.1.0

Published

Simple test runner to run test standalone with console stub.

Readme

@mizchi/testio

Simple test runner to run test standalone with console stub.

Test is incremental. Just run tests in related scope.

Support node and deno.

Concepts

  • Lightweight and no dependency.
  • Inline code testing helper. All files are executable as test runner.
  • Drop test codes by terser DCE.
  • Stub console to hydrate logs at fail only.

How to use

yarn add @mizchi/testio esbuild esbuild-register --dev
# esbuild(-register) is optional for typescript

(esbuild-node is not suitable because it removes require.main)

simple

// hello.ts
export function add(a: number, b: number) {
  return a + b;
}

import { test, run, is } from "@mizchi/testio";
test("test1", () => {});
run();

run

$ node -r esbuild-register hello.js
=== PASS: test1

with many files + DCE friendly

Simple code always runs by import and bundler includes it. With many files, other logs are annoying.

Write code for dead code ellimination(DCE) and entry detecting.

export function add(a: number, b: number) {
  return a + b;
}

/* === testio start === */
import { test, run, is, err } from "@mizchi/testio";
const isMain = require.main === module;
if (process.env.NODE_ENV === "test") {
// or main only.
// if (process.env.NODE_ENV === "test" && isMain) {
  test("test1", () => {
    console.log("do not show this message on success");
    is(add(1, 1), 2);
    err(() => is(add(1, -1), 3));
  });
  test("test2", () => {
    is(sub, 1);
  });
  run({ isMain });
}

Run

$ NODE_ENV=test node -r esbuild-register add.ts
=== PASS: test1
=== PASS: test2

See example/*.ts

Drop tests in Build: Vite Example

Define process.env.NODE_ENV=production and require.main === module

vite example.

// vite.config.ts
import { defineConfig } from "vite";
export default defineConfig({
  define: {
    "process.env.NODE_ENV": JSON.stringify("production"),
    "require.main === module": JSON.stringify(false),
  },
});

or DefinePlugin | webpack and others.

easy assertion tool (or use other assertion)

is() and err() are bundled.

  • is(a, b): void: helper match partially.
  • err(fn: () => void | Promise<void>): void: catches throw. fn should throw.
import {is, err, ANY} from "@mizchi/testio";
is(false, ANY);
is(1, 1);
is({ a: 1 }, { a: 1 });
err(() => is(1, 0));
is({ a: 1, b: 2 }, { a: 1 });
is({ a: 1, b: 2 }, {});

err(() => is({ a: 1 }, { a: 2 }));
is([1], []);
is([1], [1]);
is([1, 2, 0], [1, ANY, ANY]);
is([1, 2, 0], [1, ANY, ANY, ANY]);
err(() => is([], [1]));
err(() => is(null, [1, 2]));
err(() => is([1, 2, 1], [1, 3]));
err(() => is({ a: { b: 1 } }, { a: { b: 2 } }));

In complex case, use your favorite assertion library.

Snippets

Node: run with dependency tests

/* === testio start === */
import { run, test } from "@mizchi/testio";
const isMain = require.main === module;
if (process.env.NODE_ENV === "test") {
  test("ok", () => {
    // write here
  });
  run({ isMain });
}

I reccomend this and run all tests by eg. src/index.ts.

Node: run as main only

with cancelAll() before run.

/* === testio start === */
import { run, test, cancelAll } from "@mizchi/testio";
const isMain = require.main === module;
if (process.env.NODE_ENV === "test") {
  cancelAll();
  test("ok", () => {
    // write here
  });
  run({ isMain });
}

It's helpful hack if you want with dependency mode and cancel others.

with Deno

CAUTION I DO NOT reccomend to leave test codes on deno because it causes runtime cost on any case. If you want to use, comment out is needed.

/* === testio start === */
import { run, test } from "http://cdn.skypack.dev/@mizchi/testio";
const isMain = import.meta.main;
if (isMain) {
  test("ok", () => {
    // write here
  });
  run({ isMain });
}

Related

LICENSE

MIT