{"id":10845,"library":"espower-typescript","title":"espower-typescript","description":"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.","status":"maintenance","version":"10.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/power-assert-js/espower-typescript","tags":["javascript","power-assert","typescript"],"install":[{"cmd":"npm install espower-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add espower-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add espower-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for TypeScript compilation.","package":"typescript","optional":false},{"reason":"Used internally for TypeScript compilation and runtime execution.","package":"ts-node","optional":false}],"imports":[{"note":"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.","wrong":"import assert from 'assert';","symbol":"assert (Node.js built-in module)","correct":"import assert = require('assert');"},{"note":"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.","wrong":"import { guess } from 'espower-typescript';","symbol":"espower-typescript/guess (Mocha hook)","correct":"mocha --require espower-typescript/guess"},{"note":"When type checking is enabled (default since v9.0.0), TypeScript definition files for Node.js globals are often required to prevent compilation errors.","symbol":"@types/node","correct":"npm install -D @types/node"},{"note":"When type checking is enabled (default since v9.0.0), TypeScript definition files for Mocha globals are often required for test files.","symbol":"@types/mocha","correct":"npm install -D @types/mocha"}],"quickstart":{"code":"npm install -D espower-typescript power-assert mocha typescript @types/node @types/mocha\n\n// test/test.ts\nimport assert = require('assert');\n\ndescribe('Array#join', () => {\n  it('joins all elements into a string with separator', () => {\n    // This assertion is intentionally designed to fail to demonstrate power-assert's output.\n    assert(['a', 'b', 'c'].join(':') === 'a:b:c:');\n  });\n});\n\n// To run tests from your terminal:\n// ./node_modules/.bin/mocha --require espower-typescript/guess \"test/**/*.ts\"\n\n// Expected (failing) output will include detailed power-assert instrumentation:\n// AssertionError [ERR_ASSERTION]:   # test.ts:6\n//\n//   assert(['a','b','c'].join(':') === 'a:b:c:')\n//          |             |         |\n//          [\"a\",\"b\",\"c\"] \"a:b:c\"   false","lang":"typescript","description":"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."},"warnings":[{"fix":"Upgrade your Node.js environment to version 10 or newer.","message":"espower-typescript v10.x and newer requires Node.js v10.x or higher. Older Node.js versions are no longer supported.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Update the `typescript` package in your project to version 2.7 or later (`npm install typescript@latest`).","message":"espower-typescript v10.x and newer requires TypeScript v2.7 or higher. Ensure your project's `typescript` peer dependency meets this requirement.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Explicitly add `typescript` to your project's devDependencies: `npm install -D typescript`.","message":"Since 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.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Install necessary type definitions: `npm install -D @types/node @types/mocha`.","message":"From 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.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Always use the CommonJS-style `import assert = require('assert')` for the assertion module when using `espower-typescript`.","message":"You 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.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consult the `ts-node` v9 release notes and adjust any `ts-node` specific environment variables or configurations if issues arise.","message":"The 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.","severity":"breaking","affected_versions":">=10.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install `typescript` as a devDependency: `npm install -D typescript`.","cause":"`typescript` is a peer dependency but is not installed in the project or its version is incompatible.","error":"Cannot find module 'typescript'"},{"fix":"Install the missing type definitions: `npm install -D @types/node`.","cause":"Type checking is enabled by default, and `@types/node` (or other required `@types` packages) is missing.","error":"TS2307: Cannot find module '@types/node'"},{"fix":"Ensure you are using `import assert = require('assert')` for the `assert` module in your test files.","cause":"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')`.","error":"AssertionError: Expected true to be false"},{"fix":"Verify your Node.js version is >=10.x. Update Node.js if necessary.","cause":"This can occur due to Node.js version incompatibility, especially with older Node.js versions no longer supported by `espower-typescript`.","error":"Error: The 'mocha' command failed with exit code 1. You may need to update 'mocha' or 'espower-typescript'."}],"ecosystem":"npm"}