Better Node Test

0.8.4 · active · verified Sun Apr 19

Better Node Test (BNT) is a command-line interface (CLI) tool designed to streamline the usage of Node.js's native `node --test` runner. It significantly enhances the testing workflow by providing out-of-the-box support for TypeScript, a convenient `-t` shortcut for filtering and running specific tests by name, and integrated code coverage analysis through the `--coverage` flag. The current stable version is 0.8.4, with releases showing a consistent cadence of minor and patch updates, often addressing compatibility with evolving Node.js features like `strip-types` and robust coverage reporting. BNT differentiates itself by leveraging Node.js's built-in testing capabilities, minimizing reliance on additional third-party test runners, while adding essential developer conveniences like automatic TypeScript compilation and comprehensive coverage reporting tailored for modern Node.js environments.

Common errors

Warnings

Install

Quickstart

Demonstrates creating a simple Node.js test file with TypeScript and running it using `better-node-test` with various CLI options, including coverage and test filtering.

import assert from 'node:assert/strict';
import { test } from 'node:test';

// Save this content as 'test/example.test.ts'

test('basic math works', () => {
  assert.strictEqual(1 + 1, 2, 'Addition should be correct');
});

test('async operation', async () => {
  const result = await Promise.resolve('data');
  assert.strictEqual(result, 'data', 'Async result should match');
});

test('array includes item', () => {
  const arr = [1, 2, 3];
  assert.ok(arr.includes(2), 'Array should include 2');
});

// To install better-node-test:
// npm install --save-dev better-node-test

// To run all tests and get coverage (100% threshold, excluding test files from coverage calculation):
// npx bnt --coverage 100 --coverage-exclude '**/*.test.*'

// To run a specific test by name:
// npx bnt test/example.test.ts -t 'basic math works'

// To run all tests:
// npx bnt

view raw JSON →