espower-typescript

10.0.1 · maintenance · verified Sun Apr 19

espower-typescript is an instrumentation library that integrates `power-assert` with TypeScript projects, enabling rich, detailed assertion messages for test failures. It functions as a `mocha` `--require` hook, transforming TypeScript test files (`.ts`, `.tsx`) on the fly to inject power-assert's expressive assertions. The current stable version is 10.0.1. It aims to maintain compatibility with specific TypeScript versions (v2.7+ for v10.x) and Node.js environments (v10+), typically updating to align with major `ts-node` or `typescript` releases rather than a fixed cadence. Its key differentiators include a zero-config mode, automatic `tsconfig.json` detection, internal reliance on `ts-node` for compilation, and support for JSX/React and `allowJs` configurations.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install espower-typescript with its common peer dependencies and run a simple, failing TypeScript test with Mocha to show power-assert's detailed output.

npm install -D espower-typescript power-assert mocha typescript @types/node @types/mocha

// test/test.ts
import assert = require('assert');

describe('Array#join', () => {
  it('joins all elements into a string with separator', () => {
    // This assertion is intentionally designed to fail to demonstrate power-assert's output.
    assert(['a', 'b', 'c'].join(':') === 'a:b:c:');
  });
});

// To run tests from your terminal:
// ./node_modules/.bin/mocha --require espower-typescript/guess "test/**/*.ts"

// Expected (failing) output will include detailed power-assert instrumentation:
// AssertionError [ERR_ASSERTION]:   # test.ts:6
//
//   assert(['a','b','c'].join(':') === 'a:b:c:')
//          |             |         |
//          ["a","b","c"] "a:b:c"   false

view raw JSON →