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

@mitranim/test

v0.1.2

Published

Tiny utils for JS tests and benchmars. Similar to Deno's std/testing, but runs in all environments.

Downloads

5

Readme

Overview

Tiny utils for JS tests and benchmarks. Similar to https://deno.land/std/testing, but runs in all environments: browsers, Deno, Node, and possibly more.

Important non-features:

  • No CLI.
  • Doesn't require Node or Deno.
  • Doesn't require TypeScript.
  • No dependencies.
  • No slowness.

Features:

  • Tiny. Dependency-free. Single file. Native JS module. Can be imported by URL.
  • Runs in all environments: browsers, Deno, Node, possibly more.
  • Assertion shortcuts such as is, eq, ok, and more.
  • Filter tests by name.
  • Filter benchmarks by name.
  • Multiple benchmarking strategies.
    • TimeRunner: by total runtime in ms.
    • CountRunner: by run count.
    • Pluggable: bring your own runner.
  • Multiple reporting strategies.
    • Can report start, end, timing, number of runs, in any combination.
    • Pluggable: bring your own reporter.
  • Test and benchmark functions must be named.
    • Functions are registered and filtered by their name, not by an arbitrary string. This forces them to be indexable and searchable in editors.
  • Benchmarks support warmup for stable results.
  • Benchmark precision is tuned to 1/10th of a nanosecond.
    • Tested in Deno with --allow-hrtime.
  • Platform-agnostic console clearing.
  • Platform-agnostic OS args (nop in browser).
  • CLI flag parsing.
  • Non-verbose. Tests are silent by default.

Limitations

  • Undocumented, or rather documented only through comments. Read the source. Docs are planned but not written yet.
  • Only synchronous. Async support is planned but not implemented.
  • No support for additional messages accompanying failed tests.
  • No support for timeouts. A hanged test stays hanged.

Gotchas

Deno requires --allow-hrtime for better benchmark precision and --unstable for measuring terminal width.

Performance is variable due to factors such as JIT tiers, CPU boost, inline caching, and possibly more. Code affects other code. Order is significant. Benchmarks affect each other. Consider calling deopt before benches.

Timing precision varies by JS engine and environment.

Usage

Simple testing example:

import * as t from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected]/test.mjs'

t.test(function test_some_feature() {
  t.eq(someFunction(someInputs), `expected result`)
})

Simple benchmarking example:

import * as t from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected]/test.mjs'

t.bench(function bench_some_feature() {
  someFunction(someInputs)
})

t.deopt()
t.benches()

Complex example:

import * as t from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected]/test.mjs'

// Optional CLI flag parsing.
const cli = t.Args.os()

// Optional filtering.
t.conf.testFilterFrom(cli.get(`test`))
t.conf.benchFilterFrom(cli.get(`bench`))

// Optional bench adjustment. Can be overridden per-function.
t.conf.benchRunner = new t.TimeRunner(1024)

// Filterable tests with assertion shortcuts.
t.test(function test_some_feature() {
  t.eq(someFunction(someInputs), `expected result`)
})

// Easy and precise benchmarks.
t.bench(function bench_some_feature() {
  someFunction(someInputs)
})

t.deopt()
t.benches()

License

https://unlicense.org