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

testmatrix-compat

v0.1.2

Published

Declarative test runner for JavaScript.

Readme

Testmatrix npm

Testmatrix is a declarative test runner for JavaScript.

Installation

npm i testmatrix

Getting started

Let's start with a basic test to learn how Testmatrix works. Create a new test.js file and export your test suite.

exports.default = {
  "array.indexOf()": [
    {
      test: "returns the index at which a given element is in the array",
      assert: (a, b) => a === b,
      actual: ["A", "B", "C"].indexOf("A"),
      expected: 0
    }
  ]
}

Every key in your suite object designates a test group. Groups are arrays of tests, where each test is represented as an object. To determine if a test passes or not, we'll compare if the actual and expected values match using the specified assert function. You can use your own assert function or choose from the included ones: equal, notEqual, deepEqual and notDeepEqual.

const { equal, notEqual, deepEqual, notDeepEqual } = require("testmatrix")

Now add a test script to your package.json file and run npm test on the command line.

{
  "scripts": {
    "test": "testmatrix test.js"
  }
}

You should see the following TAP output in your console. TAP is a popular format for reporting test results. It's easy for people to read and for machines to parse. See reporting options for more information.

$ npm test

TAP version 13
# array.indexOf()
ok 1 returns the index at which a given element is in the array

1..1
# tests 1
# pass 1

# ok

If you find that your tests are starting to look alike, break them up into functions to reduce boilerplate.

const { equal } = require("testmatrix")

exports.IndexOf = (name, { array, element, expected }) => ({
  name,
  assert: equal,
  actual: array.indexOf(element),
  expected
})

Then use it as a test factory.

const { IndexOf } = require("./IndexOf")

exports.default = {
  "array.indexOf()": [
    IndexOf("returns the index at which a given element is in the array", {
      array: ["A", "B", "C"],
      element: "A",
      expected: 0
    }),
    IndexOf("returns -1 if the given element is not in the array", {
      array: ["A", "B", "C"],
      element: "X",
      expected: -1
    })
  ]
}

The final step is to add code coverage. Code coverage measures the degree to which our code is executed when our tests run. It tells us how much of our code is used. To enable code coverage, we'll install istanbuljs/nyc and edit the test script again.

{
  "test": "nyc -r lcov testmatrix test.js && nyc report"
}

Transforming Fixtures

A test fixture is what we feed to our tests. It consists of all the values and expectations that determine if our tests pass or not. Fixtures are framework agnostic while tests are specific to a program. If the program changes we'll have to rewrite some tests, but usually not the fixtures.

Testmatrix allows us to represent tests as plain data, which we can produce from our fixtures using a relatively simple map and reduce transformations.

const { equal } = require("testmatrix")

const IndexOf = ({ name, array, element, expected }) => ({
  name,
  assert: equal,
  actual: array.indexOf(element),
  expected
})

exports.default = {
  "array.indexOf()": [
    {
      name: "returns the index at which a given element is in the array",
      array: ["A", "B", "C"],
      element: "B",
      expected: 1
    },
    {
      name: "returns -1 if the given element is not in the array",
      array: ["A", "B", "C"],
      element: "Z",
      expected: -1
    }
  ].map(IndexOf)
}

Alternatively, consider the same example using a more succinct syntax based entirely on arrays.

const { equal } = require("testmatrix")

const IndexOf = ([name, array, element, expected]) => ({
  name,
  assert: equal,
  actual: array.indexOf(element),
  expected
})

exports.default = {
  "array.indexOf()": [
    [
      "returns the index at which a given element is in the array",
      ["A", "B", "C"],
      "B",
      1
    ],
    [
      "returns -1 if the given element is not in the array",
      ["A", "B", "C"],
      "Z",
      0
    ]
  ].map(IndexOf)
}

Asynchronous Tests

We can test side effects and asynchronous code by using a function as the test's actual property. The function receives a function which must be called with the actual value after the operation is done. You are responsible for creating and destroying any resources needed to arrive at this value within this function.

TODO: Rewrite example using async functions instead?

const { equal } = require("testmatrix")

const SlowDivision = ({ name, dividend, divisor, quotient }) => ({
  name,
  assert: equal,
  actual: done =>
    setTimeout(() => {
      done(dividend / divisor)
    }, 1000),
  expected: quotient
})

exports.default = {
  "slow division": [
    SlowDivision({
      name: "divides two numbers slowly",
      dividend: 10,
      divisor: 5,
      quotient: 2
    })
  ]
}

Using ES Modules

You can use ES modules across your entire test suite via standard-things/esm.

{
  "scripts": {
    "test": "nyc -i esm -r lcov testmatrix test.js && nyc report"
  }
}

License

MIT