test

@lukekaalim/test

CircleCI

An alarmingly simple test library, made mostly to my tastes and practical needs.

Docs

Why

What

@lukekaalim/test is a small testing tool that allows you to define a set of nested expectations of your program using a basic API, and a method of printing those assertions out in various methods.

This library imposes some definitions:

A test is a program that is constructed to compare the output of another program with an expected output. A test either asserts “success” or “failure”, describing whether the output that the other program generated matched the expected output. If the test succeeds, then the program is guaranteed (or asserted) to have matched all the expectations.

An expectation is an action that can be performed to generate an “assertion”, which describes if a portion of a programs output matched an predefined rule (or set of rules, which can be recursively expectations themselves).

This library helps you build your testing program; it is not a complete testing program in and of itself. This library helps you generate “assertions” once you write your “expectations”, and also provides some helpful reporters which turn those expectations into useful things like CLI graphs, booleans, or process exit codes.

Anti-Pitch

Installation

Install with

npm i -D @lukekaalim/test

Example

// src/math.test.js
import { assert } from '@lukekaalim/test';

export const testMath = () => assert('Math should perform as expected', [
  assert('One should equal one', 1 == 1),
  assert('Two should equal two', 2 == 2),
  assert('One plus one should equal two', 1 + 1 == 2),
]);
// test.js
import { colorReporter } from '@lukekaalim/test';
import { testMath } from './src/math.test';

const testProgram = async () => {
  const report = colorReporter(testMath());
  console.log(report);
};

testProgram();

Contributing

Infra

Automated builds are provided by CircleCI

Authors

Luke Kaalim (luke@kaal.im)