ts-node-test is a command-line interface (CLI) wrapper that enables the use of Node.js's native test runner (introduced in Node.js 18.7.0) with TypeScript files. It addresses a limitation in Node.js where the built-in test runner does not natively support custom file extensions for automatic test file discovery, requiring explicit file paths for `.ts` files. This package works by recursively searching specified directories for `.ts`, `.mts`, `.cts`, `.js`, `.mjs`, and `.cjs` files, then passing the discovered files to the Node.js test runner via `ts-node` for execution. The current stable version is 0.4.4, with releases occurring intermittently, focusing on bug fixes, dependency updates, and feature parity with newer Node.js test runner flags. Its primary differentiator is simplifying the setup for TypeScript projects wanting to leverage Node.js's native testing capabilities without complex build steps or manual file listings.
npm install ts-node-testVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `ts-node-test` in a `package.json` script, along with a simple TypeScript test file using Node.js's native test runner API, including synchronous, asynchronous, mocked, and sub-tests.
Upgrade your Node.js installation to version 18.7.0 or newer. Use `nvm install 18` or `nvm install 20` and `nvm use <version>`.
Install TypeScript: `npm install -D typescript` or `yarn add -D typescript`.
Upgrade to `ts-node-test` v0.4.1 or newer. If staying on an older version, explicitly list test file paths or use fine-grained glob patterns to avoid `node_modules`.
Ensure you are using the latest version of `ts-node-test` to get full compatibility with new Node.js test runner features. Upgrade with `npm update ts-node-test`.
Install TypeScript as a dev dependency: `npm install -D typescript` or `yarn add -D typescript`.
Upgrade your Node.js environment to version 18.7.0 or newer. Consider using a tool like `nvm` to manage Node.js versions.
Ensure `TEST_EXTENSIONS` is a comma-separated string of valid extensions (e.g., `.ts,.js`). Double-check the glob patterns or file paths passed to `ts-node-test` to ensure they point to existing files.