Registry / testing / brittle

brittle

JSON →
library3.19.1jsnpmunverified

Brittle is a lightweight, modern TAP (Test Anything Protocol) test runner for JavaScript, currently stable at version 3.19.1. It provides a clean API for writing both classic callback-based and modern async/await tests, supporting features like test plans, subtests, explicit exception/execution checks, and utilities for timeouts and teardowns. A key differentiator is its support for multiple JavaScript runtimes, including Node.js, Bare, and Pear, making it suitable for a wide range of environments. While a strict release cadence isn't published, it appears to be actively maintained with regular updates. Brittle aims to be a robust yet simple testing solution, focusing on developer experience and modern JavaScript paradigms without the overhead of larger test frameworks.

npm install brittle
INSTALL
IMPORT
SIG · BRITTLE
B
brittle
testingjavascriptv3.19.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

test
import test from 'brittle'
const test = require('brittle')
Brittle v3+ is primarily an ESM package. Use `import` syntax. Default export is the `test` function.
test (named)
import { test } from 'brittle'
import * as brittle from 'brittle'; brittle.test(...)
The `test` function is also provided as a named export for explicit destructuring.
Utility functions
import { solo, skip, hook, todo, configure } from 'brittle'
import brittle from 'brittle'; brittle.solo(...)
Other test modifiers and configuration utilities are available as named exports.

Demonstrates basic synchronous and asynchronous tests, including assertions, plans, subtests, and the inverted test style.

import test from 'brittle' test('basic assertions and async behavior', async function (t) { t.plan(4) // Expect 4 assertions t.is(typeof Date.now(), 'number', 'Date.now() returns a number') t.ok(Date.now() > 0, 'Timestamp is positive') t.comment('Demonstrating async operations...') await new Promise(resolve => setTimeout(resolve, 100)) t.pass('Async operation completed') t.test('a subtest example', function (sub) { sub.plan(1) sub.alike({ a: 1 }, { a: 1 }, 'Objects should be deep equal in subtest') }) }) test('inverted test style with plan', async function (t) { t.plan(1) const result = await new Promise(r => setTimeout(() => r('done'), 50)) t.is(result, 'done', 'Inverted test can await its own completion') })
Debug
Known issues
breakingBrittle versions 3.0.0 and above are primarily designed as ES Modules (ESM). Direct `require()` statements for the main `brittle` package may lead to errors or unexpected behavior in Node.js environments unless specific CommonJS compatibility layers are used.
fix
Migrate your test files to use `import` statements (e.g., `import test from 'brittle'`). Ensure your `package.json` specifies `"type": "module"` or use a `.mjs` file extension for your test files.
affects: >=3.0.0
gotchaInverted tests (where `test()` returns an `assert` object directly) require either `t.plan(n)` to be called with the expected number of assertions, or `t.end()` must be explicitly called to signal test completion. Failure to do so will result in the test hanging or potentially not completing correctly, especially if awaited.
fix
For inverted tests, always define `t.plan(count)` at the beginning if you know the number of assertions, or explicitly call `t.end()` at the end of the test function if the number of assertions is dynamic or unknown.
affects: >=1.0.0
gotchaWhen using `await test(...)` or `await t` for inverted tests, ensure all asynchronous operations within the test are properly awaited or chained. If a test completes before its async operations finish, assertions made later might not be reported or could cause test failures due to unhandled promises.
fix
Always `await` promises returned by asynchronous functions within your tests. For inverted tests, `await t` will only resolve once `t.plan` is fulfilled or `t.end()` is called, ensuring that the main test runner waits for the inverted test's completion.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
Attempting to use `require('brittle')` in a CommonJS module when Brittle v3+ is primarily an ES Module.
fix
Update your module syntax to use `import test from 'brittle'` and ensure your Node.js environment is configured for ESM (e.g., `"type": "module"` in `package.json` or `.mjs` file extension).
ReferenceError: test is not defined
Incorrect import statement or missing `import` declaration for the `test` function in an ESM context.
fix
Ensure `import test from 'brittle'` or `import { test } from 'brittle'` is present at the top of your test file.
Test finished without asserting anything
An inverted test was created and awaited, but no `t.plan()` was set, or `t.end()` was not called.
fix
For inverted tests, add `t.plan(N)` to declare the expected number of assertions, or call `t.end()` when the test has completed its work.
Upgrade
Version history
3.19.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
brittle — npm install brittle · libregistry