ts-node-test-register is a utility package designed to simplify running TypeScript tests by integrating with test runners like Mocha. It enables the use of a dedicated `tsconfig.json` file (e.g., `test/tsconfig.json`) specifically for test code, allowing for different compiler options (like `allowJs`) compared to the main project's configuration. The package ensures type checking is active by default during testing, adhering to the principle that test code should also be type-safe. It closely tracks major releases of its peer dependency, `ts-node`, with the current stable version being 10.0.0. Its main differentiator is the automatic loading of test-specific `tsconfig.json` files and explicit enabling of type checks, providing a robust environment for TypeScript testing.
npm install ts-node-test-registerVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to configure Mocha to use `ts-node-test-register` to run TypeScript tests, loading a dedicated `test/tsconfig.json` for test-specific compiler options.
Always review the release notes for both `ts-node-test-register` and the corresponding major version of `ts-node` when upgrading. Ensure your installed `ts-node` version matches the peer dependency range specified by `ts-node-test-register`.
Install `ts-node` as a development dependency: `npm install ts-node --save-dev` or `yarn add ts-node --dev`.
Ensure your test files are free of TypeScript errors. If specific type behaviors are required for tests, configure them within your dedicated `test/tsconfig.json` to reflect the desired type-checking strictness.
Install `ts-node` as a development dependency: `npm install ts-node --save-dev` or `yarn add ts-node --dev`.
Ensure you are passing `--require ts-node-test-register` to your test command in `package.json` scripts or configuring it in your test runner's configuration file (e.g., `.mocharc.json`). Double-check the path if manually specifying it.
Address the specific TypeScript error reported. This might involve correcting type definitions, adjusting compiler options in `test/tsconfig.json`, or ensuring all dependencies are correctly typed and installed.