Socket
Socket
Sign inDemoInstall

ts-node-test

Package Overview
Dependencies
51
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ts-node-test

Use the Node.js test runner, but with TypeScript via ts-node


Version published
Weekly downloads
1.8K
decreased by-12.83%
Maintainers
1
Install size
2.51 MB
Created
Weekly downloads
 

Changelog

Source

0.4.3 (2023-09-17)

Bug Fixes

  • Simplify TEST_EXTENSIONS null/undefined check (#84) (aa92fcb)
  • Use 'node:' protocol in imports (#86) (850eb7b)

Readme

Source

ts-node-test

CI

Use the Node.js test runner, but with TypeScript via ts-node. You need to have typescript installed as a (dev) dependency and must be using Node version 18.7.0 or later.

Imagine it like ts-node --test, if that command existed.

Usage

Install as a dev dependency:

npm i -D ts-node-test

Then add a script to your package.json:

{
  "scripts": {
    "test": "ts-node-test test-file1.ts foo/test-file2.ts another-dir/"
  }
}

The command syntax is similar to node --test. Multiple paths can be passed. Directories will be searched recursively for any files with supported extensions (currently: .js, .mjs, .cjs; .ts, .mts, .cts). Then, Node's test runner will be started on all files that were found in this process.

Extensions

You can override the list of extensions by setting an environment variable (TEST_EXTENSIONS). This list will then be used instead of the default extensions. For example:

TEST_EXTENSIONS=.test.ts,.test.js ts-node-test test/

The above will recursively look for files in the test/ directory ending in .test.ts or .test.js.

CLI flags

The following additional CLI flags are supported, and will be passed along to Node.js when provided:

  • --test-name-pattern <pattern> *
  • --test-reporter <reporter> *
  • --test-reporter-destination <destination> *
  • --test-only
  • --watch
  • --watch-preserve-output
  • --experimental-test-coverage

Flags marked with * can be passed multiple times.

Why this is needed

TL;DR: Node.js (at the time of writing) does not allow to override the list of extensions that are used when searching for test files. The official recommendation is to list all files explicitly. That is precisely what this CLI wrapper does behind the scenes.

Please refer to the following issues for further information:

Keywords

FAQs

Last updated on 17 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc