A simple tap test runner that can be used by any javascript interpreter.

Overview

just-tap

A simple tap test runner that can be used in any client/server javascript app.

Installation

npm install --save-dev just-tap

Usage

import createTestSuite from 'just-tap';

const { test, run } = createTestSuite();

test('calculate 1 + 1 correctly', t => {
  t.plan(1);

  t.equal(1 + 1, 2);
});

test('calculate 1 + 1 wrong', t => {
  t.plan(1);

  t.equal(1 + 1, 3);
});

const results = await run();
// results === {
//   passed: 1, failed: 1, ok: 1, notOk: 1, skipped: 0, success: false
// }

Console output

TAP version 14
# calculate 1 + 1 correctly:
ok 1 - expected "2" to equal "2"
# calculate 1 + 1 wrong:
not ok 2 - expected "2" to equal "3"

1..2
# tests 2
# pass  1
# fail  1
# skip  0

API

The following options exist on the t object:

t.plan(assertions: number) !optional

If provided, will wait until the specified number of assertions have been made before resolving the test.

It will also fail the test if too many assertions are made.

t.timeout(milliseconds: number) !default: none

If you have an async task that is running for longer than the timeout, or you are waiting for planned assertions, then the test will fail.

t.waitFor(fn: function, timeout: number)

A promise based function that will continuously try and execute the first argument until:

  • no notOk's are raised
  • it does not throw

All assertions are discarded until the final pass.

Assertions

t.pass('passed');
t.fail('failed');
t.equal(1, 1, 'expected "1" to equal "1"');
t.notEqual(1, 2, 'expected "1" to not equal "2"');
t.looseEqual(1, '1', 'expected "1" to loose equal "1"');
t.notLooseEqual(1, '2', 'expected "1" to not loose equal "2"');
t.deepEqual({ a: 1 }, { a: 1 }, 'expected {"a":1} to deep equal {"a":1}');
t.notDeepEqual({ a: 1 }, { a: 2 }, 'expected {"a":1} to not deep equal {"a":2}');
t.ok(true, 'expected "true" to be truthy');
t.notOk(false, 'expected "false" to be falsy');

Advanced Usage

The following options are default, and don't need to be included.

const { test, run } = createTestSuite({
  // What function is used for streaming logs
  // By default logs are streamed to console.log
  logger: console.log,

  // How many tests will run at the same time?
  // By default, all run at once.
  concurrency: Infinity,

  // This adds a small amount of color
  // You can override these `text => text`
  formatInfo: text => `\x1b[96m${text}\x1b[39m\x1b[39m`,
  formatDanger: text => `\x1b[91m${text}\x1b[39m\x1b[39m`,
  formatSuccess: text => `\x1b[92m${text}\x1b[39m\x1b[39m`
});

But this means as the tests are run, the results are instantly outputted to the console.log. Depending on your use case, you may want to accumulate them instead.

const log = [];
const { test, run } = createTestSuite({
  logger: (...args) => log.push(args),
});

const results = await run();
if (!results.success) {
  console.log(log);
}

Why another test runner?

Most test runners include a lot of features and do a lot of magic.

They automatically (magically?):

  • search and include test files
  • run the tests for you
  • inject test methods like describe/it
  • add a hooks system for managing before/after events
  • use cli's to manage the auto inclusion of the test runner
  • use event systems for capturing when tests fail/succeed/finish

These features can create a great foundation for writing and running tests, but they also come with their own management and overhead.

This library aims to provide a bare bones test runner with zero magic.

As such, it can run in a web browser, nodejs, deno or any other javascript interpreter.

It's also pretty fast, small and has zero dependencies;

You might also like...

A Typescript assembly(ish) interpreter with a nice web UI

Assembly-Online Example Fibonacci Program MOV R0, #1 MOV R1, #1 fib: MOV R2, R0 ADD R0, R0, R1 MOV R1, R2 B print CMP R0, #40 BGT exit B fib exit: \ I

May 23, 2022

🏆 2nd Runner Up 🏆 at Vividthata A Blend of ideas By NIT Hamirpur

🏆 2nd Runner Up 🏆 at Vividthata A Blend of ideas By NIT Hamirpur

Index Problem Statement Solution Proposed How it Works Challenges we faced Running Locally Demonstration Glimpse Problem Statement It is often the cas

Nov 22, 2022

A Jest runner that runs tests directly in bare Node.js, without virtualizing the environment.

jest-light-runner A Jest runner that runs tests directly in bare Node.js, without virtualizing the environment. Comparison with the default Jest runne

Dec 12, 2022

Dead-simple CORS handling for any itty-router API (test with Cloudflare Workers, but works anywhere)!

Dead-simple CORS handling for any itty-router API (test with Cloudflare Workers, but works anywhere)!

Simple CORS-handling for any itty-router API. Designed on Cloudflare Workers, but works anywhere. Features Tiny. Currently ~600 bytes, with zero-depen

Dec 16, 2022

Jester is a test-generation tool to create integration test code.

Jester is a test-generation tool to create integration test code.

Code Generator for Integration Tests Introduction Welcome to Jester: An easy-to-use web application that helps you create and implement integration te

Dec 12, 2022

Twitter Text Libraries. This code is used at Twitter to tokenize and parse text to meet the expectations for what can be used on the platform.

twitter-text This repository is a collection of libraries and conformance tests to standardize parsing of Tweet text. It synchronizes development, tes

Jan 8, 2023

this is a single-page web application. we built a book website where the user can add , remove and display books. we used modules to implement these functionalities. also, we used the Date class to display the date and time.

Awsome Books In this Project, we have built A Books websites. Built With 🔨 HTML CSS javascript Git & Github Live Demo Here you can find the live Demo

Aug 3, 2022

A frida script that can be used to find the public RSA key used in the native libakamaibmp.so shared library, seen in version 3.3.0 of Akamai BMP

A frida script that can be used to find the public RSA key used in the native libakamaibmp.so shared library, seen in version 3.3.0 of Akamai BMP

Akamai BMP - RSA/AES Frida Hook This Frida script can be used to find the public RSA key used in the encryption process in Akamai BMP 3.3.0. Since ver

Jan 8, 2023
Releases(v1.5.0)
A leetcode workspace template with test case runner for JavaScript/TypeScript programmers.

leetcode-typescript-workspace English | įŽ€äŊ“中文 A vscode workspace template with test case runner script for JavaScript/TypeScript programmers using exte

null 10 Dec 13, 2022
A new zero-config test runner for the true minimalists

Why User-friendly - zero-config, no API to learn, simple conventions Extremely lighweight - only 40 lines of code and no dependencies Super fast - wit

null 680 Dec 20, 2022
A low-feature, dependency-free and performant test runner inspired by Rust and Deno

minitest A low-feature, dependency-free and performant test runner inspired by Rust and Deno Simplicity: Use the mt test runner with the test function

Sondre Aasemoen 4 Nov 12, 2022
A simple handle tap and hold action for Svelte/SvelteKit.

Svelte Tap Hold Minimalistic tap and hold component for Svelte/SvelteKit, see demo here. Installation // Using Yarn to install yarn add --dev svelte-t

Binsar Dwi Jasuma 9 Dec 8, 2022
This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do any operations that can be performed in python shell with this package.

Django execute code This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do

Shinu 5 Nov 12, 2022
A lightweight normalized tap event

?? Retired: Tappy! Per our unmaintained repository status documentation this repository is now retired and is no longer accepting issue reports or pul

Filament Group 573 Dec 9, 2022
An interpreter for College Board's specified pseudocode for the AP Computer Science Principles Exam.

College Board Pseudocode Interpreter A playground for this interpreter is up on my website. This project is a mostly-functioning interpreter for Colle

Daniel 7 Nov 16, 2022
Detect the executable python interpreter cmd in $PATH.

detect-python-interpreter Detect the executable python interpreter cmd in $PATH. Installation $ npm install --save detect-python-interpreter Usage con

Khaidi Chu 2 Apr 12, 2022
A Brainf*ck interpreter built in the TypeScript type system.

Brainf*ck Interpreter in the TypeScript type system Just another thing that no one asked for. Why? I love messing with the TypeScript type system. Som

Carter Snook 55 Dec 17, 2022
A browser-based Piet editor/interpreter

A browser-based Piet editor/interpreter Features An interpreter that fully conforms to the Piet specification Code editor with a palette with command

null 8 Nov 22, 2022