Registry / testing / test
library3.3.0jsnpmunverified

This package, `test`, provides a user-land backport of the experimental `node:test` module, originally introduced in Node.js 18. It allows developers to utilize the same standardized testing API in Node.js environments from version 14 and later. The current stable version is 3.3.0, released in early 2023, with subsequent maintenance releases as needed. The project maintains a feature-driven release cadence, closely mirroring updates and enhancements in the core `node:test` module. Its key differentiators include minimal runtime dependencies, a comprehensive test suite to ensure robust compatibility with Node.js core, and the crucial ability to introduce modern `node:test` capabilities to older Node.js versions without requiring core upgrades. Unlike the core implementation, it does not hide its own stack frames, offering slightly different debugging clarity.

npm install test
INSTALL
IMPORT
SIG · TEST
T
test
testingjavascriptv3.3.0
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 'test'
import { test } from 'test'
The primary function for defining tests. It is the default export in ESM. For CommonJS, use `const test = require('test')`.
describe, it
import { describe, it } from 'test'
import describe from 'test'
Aliases for the `test` function, often preferred for BDD-style test suites. These were exposed since v3.1.0.
MockTracker
import { MockTracker } from 'test'
A utility class for creating mocks. This feature was added in v3.3.0.
TestContext (type)
import type { TestContext } from 'test'
import { TestContext } from 'test'
The interface for the test context object passed to test functions. Use a type import to prevent runtime imports of types.

Demonstrates basic synchronous, asynchronous (Promise and callback), and subtest creation, including a skipped test, using the `test` API.

import test from 'test'; import assert from 'node:assert'; test('synchronous passing test', t => { assert.strictEqual(1, 1); }); test('asynchronous passing test', async t => { await new Promise(resolve => setTimeout(resolve, 50)); assert.strictEqual(1, 1); }); test('callback passing test', (t, done) => { setImmediate(() => { assert.strictEqual(true, true); done(); }); }); test('top level test with subtests', async t => { await t.test('subtest 1', t => { assert.strictEqual(1, 1); }); await t.test('subtest 2', t => { assert.strictEqual(2, 2); }); }); test('skipped test', { skip: 'reason' }, t => { // This test will be skipped assert.fail('This should not run'); });
Debug
Known issues
breakingIn v3.0.0, the project moved its repository and ownership to the Node.js organization (`nodejs/node-core-test`). While the npm package name remains `test`, users referencing the old GitHub repository (`juliangruber/node-core-test`) or making assumptions about governance should be aware of this change.
fix
Update any direct GitHub repository references to `https://github.com/nodejs/node-core-test`.
affects: >=3.0.0
gotchaWhen running on Node.js v14.x, some features (particularly those relying on `AbortSignal` for test termination and cancellation) require the `--experimental-abortcontroller` CLI flag to be enabled. Without this flag, certain test functionalities might not work as expected.
fix
Pass `NODE_OPTIONS='--experimental-abortcontroller'` in your environment when running tests on Node.js v14.x. For v14.x, consider adding `--no-warnings` to suppress experimental feature warnings.
affects: >=1.0.0 <15.0.0
gotchaParent tests do not implicitly wait for their subtests to complete. If you define subtests within an `async` parent test, you *must* use `await t.test()` for each subtest to ensure they run to completion and their results are correctly factored into the parent's outcome. Unawaited subtests will be cancelled and treated as failures.
fix
Always `await` calls to `t.test()` when defining subtests within an `async` parent test function.
affects: >=1.0.0
gotchaPrior to v3.2.1, the test runner could encounter issues when `AbortSignal` support was entirely absent. While v3.2.1 fixed a bug to make it work even without full `AbortSignal` support, older versions might exhibit less robust behavior related to test cancellation or timeouts in environments lacking this API.
fix
Upgrade to v3.2.1 or newer to ensure the test runner works reliably across various `AbortSignal` support levels. For Node.js v14.x, continue to use `--experimental-abortcontroller` for full functionality.
affects: <3.2.1
Errors
Common errors & fixes
Test failure: Parent test completed before subtest finished.
An asynchronous subtest was started but not `await`ed by its parent test, causing the parent to complete prematurely and the subtest to be cancelled and reported as a failure.
fix
Ensure all calls to `t.test()` within an `async` parent test function are `await`ed, e.g., `await t.test('my subtest', ...)`.
TypeError: (0 , test__WEBPACK_IMPORTED_MODULE_0__.default) is not a function
This typically occurs in bundled environments (like Webpack) when mixing ESM `import` with CJS `require` semantics, or incorrectly trying to import the default `test` function as a named export.
fix
For ESM, use `import test from 'test'`. For CommonJS, use `const test = require('test')`. Ensure your bundler configuration correctly handles module interop. If the issue persists, try `import * as testModule from 'test'; testModule.default('my test', ...);`.
Test timed out
An asynchronous test (either Promise-based or callback-based) did not resolve its Promise or call its `done` callback within the default timeout period.
fix
Review the asynchronous operations within the test to ensure they complete. If the operation is genuinely long-running, increase the test's timeout using the `{ timeout: milliseconds }` option in `test()`.
Upgrade
Version history
3.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
test — npm install test · libregistry