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-formatterNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create and use the formatter to format an assertion error with a diff between two arrays.
Consider using the newer power-assert packages or directly using power-assert-runtime/power-assert-renderer* if upgrading to power-assert v2+.
Use require() directly, or use a bundler/transpiler if you need ESM. If using TypeScript, set "esModuleInterop": true and use default import.
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.
Pass options.maxDepth with a higher value (e.g., 5 or Infinity) to show deeper object structures.
Example: const formatter = createFormatter({ maxDepth: 10 });Use const createFormatter = require('power-assert-formatter'); or import createFormatter from 'power-assert-formatter'; (with esModuleInterop).Run npm install power-assert-formatter --save-dev in your project.
Use power-assert's assert module (via require('power-assert') or wrapped with empower) to generate assertions that produce proper context.Use CommonJS require() or enable compatibility (e.g., createRequire from 'module') in ESM context.
No dependency data recorded yet.