Registry / testing / espower-typescript

espower-typescript

JSON →
library10.0.1jsnpmunverified

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.

npm install espower-typescript
INSTALL
IMPORT
SIG · ESPOWER-TYPESCRIPT
E
espower-typescript
testingjavascriptv10.0.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.

assert (Node.js built-in module)
import assert = require('assert');
import assert from 'assert';
For `power-assert` instrumentation to work correctly with `espower-typescript`, the CommonJS-style `require` syntax is mandatory for importing Node's built-in `assert` module. Direct ES module imports for `assert` will bypass instrumentation.
espower-typescript/guess (Mocha hook)
mocha --require espower-typescript/guess
import { guess } from 'espower-typescript';
This package is primarily consumed as a Mocha `--require` hook to preprocess TypeScript test files. It is not intended for direct JavaScript `import` statements within your application code.
@types/node
npm install -D @types/node
When type checking is enabled (default since v9.0.0), TypeScript definition files for Node.js globals are often required to prevent compilation errors.
@types/mocha
npm install -D @types/mocha
When type checking is enabled (default since v9.0.0), TypeScript definition files for Mocha globals are often required for test files.

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
Debug
Known issues
breakingespower-typescript v10.x and newer requires Node.js v10.x or higher. Older Node.js versions are no longer supported.
fix
Upgrade your Node.js environment to version 10 or newer.
affects: >=10.0.0
breakingespower-typescript v10.x and newer requires TypeScript v2.7 or higher. Ensure your project's `typescript` peer dependency meets this requirement.
fix
Update the `typescript` package in your project to version 2.7 or later (`npm install typescript@latest`).
affects: >=10.0.0
breakingSince v9.0.0, `typescript` must be installed as a local dependency in your project (e.g., `npm install -D typescript`), rather than relying on global installations or internal transitive dependencies.
fix
Explicitly add `typescript` to your project's devDependencies: `npm install -D typescript`.
affects: >=9.0.0
breakingFrom v9.0.0, type checking is enabled by default internally via `ts-node`. This requires `@types/node` and `@types/mocha` (or similar `@types` packages for other test runners) to be installed as devDependencies.
fix
Install necessary type definitions: `npm install -D @types/node @types/mocha`.
affects: >=9.0.0
gotchaYou MUST use `import assert = require('assert')` for Node.js's built-in `assert` module. Using `import assert from 'assert'` will prevent `power-assert` instrumentation from working correctly, resulting in generic assertion errors.
fix
Always use the CommonJS-style `import assert = require('assert')` for the assertion module when using `espower-typescript`.
affects: >=0.0.0
breakingThe internal `ts-node` dependency was updated from v8 to v9 in v10.0.0. Users relying on specific `ts-node` behaviors or configurations might need to review `ts-node`'s v9 release notes for compatibility.
fix
Consult the `ts-node` v9 release notes and adjust any `ts-node` specific environment variables or configurations if issues arise.
affects: >=10.0.0
Errors
Common errors & fixes
Cannot find module 'typescript'
`typescript` is a peer dependency but is not installed in the project or its version is incompatible.
fix
Install `typescript` as a devDependency: `npm install -D typescript`.
TS2307: Cannot find module '@types/node'
Type checking is enabled by default, and `@types/node` (or other required `@types` packages) is missing.
fix
Install the missing type definitions: `npm install -D @types/node`.
AssertionError: Expected true to be false
This is a generic assertion error, indicating that `power-assert` instrumentation failed. A common cause is using `import assert from 'assert'` instead of `import assert = require('assert')`.
fix
Ensure you are using `import assert = require('assert')` for the `assert` module in your test files.
Error: The 'mocha' command failed with exit code 1. You may need to update 'mocha' or 'espower-typescript'.
This can occur due to Node.js version incompatibility, especially with older Node.js versions no longer supported by `espower-typescript`.
fix
Verify your Node.js version is >=10.x. Update Node.js if necessary.
Upgrade
Version history
10.0.1latest on npm
Audit
Dependencies
typescriptrequiredPeer dependency for TypeScript compilation.
ts-noderequiredUsed internally for TypeScript compilation and runtime execution.
Agent activity
2 hits · last 30 days
node
2
Resources
espower-typescript — npm install espower-typescript · libregistry