Registry / testing / power-assert-formatter

power-assert-formatter

JSON →
library1.4.1jsnpmunverified

A formatter module for Power Assert output that provides detailed, human-readable failure messages for test assertions. Version 1.4.1 is stable but effectively in maintenance mode as the package is part of the larger power-assert ecosystem. It formats assertion errors with diff output, object depth control, circular structure handling, and configurable stringification. Unlike simple assert libraries, power-assert-formatter enables rich, contextual failure messages without requiring special assertion APIs. Its output is highly customizable via options like lineDiffThreshold, maxDepth, and outputOffset. The package is primarily used in testing frameworks like Mocha or Node's assert module alongside power-assert.

npm install power-assert-formatter
INSTALL
IMPORT
SIG · POWER-ASSERT-FORMA
P
power-assert-formatter
testingjavascriptv1.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

createFormatter
const createFormatter = require('power-assert-formatter')
import createFormatter from 'power-assert-formatter'
The package exports a single function via module.exports = createFormatter, so CommonJS require is correct. There is no ES module build; direct import will fail in native ESM environments without a bundler or transpiler.
createFormatter
import createFormatter from 'power-assert-formatter'
import { createFormatter } from 'power-assert-formatter'
The package does not export a named export; it exports a single function as default via module.exports. In TypeScript or with esModuleInterop, the default import works, but named import fails.
defaultOptions
createFormatter.defaultOptions()
import { defaultOptions } from 'power-assert-formatter'
defaultOptions is a static method on the createFormatter function object, not a separate export. Use createFormatter.defaultOptions() to get default options.

Shows how to create and use the formatter to format an assertion error with a diff between two arrays.

const createFormatter = require('power-assert-formatter'); const assert = require('assert'); // Create a formatter with default options const formatter = createFormatter(); // Example assertion failure (simulating power-assert enhanced assert) const a = [1, 2, 3]; const b = [1, 2, 4]; try { assert.deepStrictEqual(a, b); } catch (e) { const formatted = formatter(e); // outputs formatted failure message console.log(formatted); } // If using power-assert, the formatter integrates automatically; // this is just a basic usage example.
Debug
Known issues
deprecatedpower-assert-formatter is part of the older power-assert v1 ecosystem; newer versions of power-assert use power-assert-runtime and power-assert-renderer* packages. This package is effectively in maintenance mode and not actively developed.
fix
Consider using the newer power-assert packages or directly using power-assert-runtime/power-assert-renderer* if upgrading to power-assert v2+.
affects: >=0.0.0
gotchaThe package does not provide a native ES module (ESM) build. Using import in Node.js without a transpiler will fail.
fix
Use require() directly, or use a bundler/transpiler if you need ESM.
If using TypeScript, set "esModuleInterop": true and use default import.
affects: >=1.0.0
gotchaThe formatter expects a specific error object structure created by power-assert (or empower). Passing a plain Error or AssertionError may produce incomplete output.
fix
Ensure the error object is generated by power-assert's enhanced assert or by empower wrapper.
If you see missing diff or content, check that the error has `powerAssertContext` property.
affects: >=0.0.0
gotchaThe default value for maxDepth is 1, which may truncate deep objects too aggressively in assertions. Users often expect full object representation.
fix
Pass options.maxDepth with a higher value (e.g., 5 or Infinity) to show deeper object structures.
Example: const formatter = createFormatter({ maxDepth: 10 });
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: createFormatter is not a function
Incorrect import: using named import from ESM style but package exports a CommonJS module with module.exports = function.
fix
Use const createFormatter = require('power-assert-formatter'); or import createFormatter from 'power-assert-formatter'; (with esModuleInterop).
Error: Cannot find module 'power-assert-formatter'
Missing installation or incorrect npm package name.
fix
Run npm install power-assert-formatter --save-dev in your project.
AssertionError: [undefined] no diff output
The error object passed to the formatter is not a power-assert-enhanced error; missing powerAssertContext property.
fix
Use power-assert's assert module (via require('power-assert') or wrapped with empower) to generate assertions that produce proper context.
SyntaxError: Unexpected token 'export'
Trying to import the package in a Node.js ESM context without a bundler, but the package uses CommonJS and doesn't export ESM.
fix
Use CommonJS require() or enable compatibility (e.g., createRequire from 'module') in ESM context.
Upgrade
Version history
1.4.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
power-assert-formatter — npm install power-assert-formatter · libregistry