Skip to content

Commit

Permalink
feat: Add initial implementation (#1)
Browse files Browse the repository at this point in the history
Release-As: 0.1.0
  • Loading branch information
meyfa authored Jul 29, 2022
1 parent b9ba52b commit 4a5d722
Show file tree
Hide file tree
Showing 12 changed files with 4,924 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extends: '@meyfa/eslint-config'
parserOptions:
project: './tsconfig.lint.json'
36 changes: 36 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches:
- main
pull_request:

jobs:
lint:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
- run: npm ci
- run: npm run lint

test:
name: test - Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 18
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- run: npm test
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
.idea
node_modules/
/dist
.nyc_output
/coverage
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# ts-node-test
Use the Node.js test runner, but with TypeScript via ts-node

[![CI](https://github.com/meyfa/ts-node-test/actions/workflows/main.yml/badge.svg)](https://github.com/meyfa/ts-node-test/actions/workflows/main.yml)

Use the [Node.js test runner](https://nodejs.org/dist/latest-v18.x/docs/api/test.html), 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.

### How to use

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.

### 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:

* [Node.js #44023](https://github.com/nodejs/node/issues/44023)
* [ts-node #1853](https://github.com/TypeStrong/ts-node/issues/1853)
Loading

0 comments on commit 4a5d722

Please sign in to comment.