Skip to content

Commit

Permalink
3 testing (#4)
Browse files Browse the repository at this point in the history
* ncu

* add mocha chai to dev

* Update README.md

* npm test

* Add node GitHub Action

* helper method `run`

* check action pwd

* clean build -> dist/src

* test age
  • Loading branch information
drernie authored Sep 16, 2023
1 parent d4d0810 commit b438302
Show file tree
Hide file tree
Showing 5 changed files with 1,002 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ jobs:
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: pwd
- run: ls -la dist
- run: npm test
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@ Demo project to create/test CLIs written using TypeScript
It is surprisingly difficult to find a currently-working example of how
to create and test Command-Line Interfaces (CLIs) written in TypeScript.

# Purpose

This project updates the
[How to Create a Testable CLI using TypeScript?](https://www.realpythonproject.com/how-to-create-a-testable-cli-using-typescript/)
from Jan 2023 with various fixes that were not obvious (at least to me).

These include:

* Restricting to "chalk": "^4.1.2"
* Restricting "chalk" to "^4.1.2"
* Avoiding the confusingly-named 'npm run install'
* import { expect } from "chai";
* "test" : "mocha --require ts-node/register test/**/*.ts"
* Add node GitHub Action (tests dist/src/index.js, not installed version)

## Functionality

Use `npm run` to see all commands:
## Usage

```bash
$ npm run hello
$ npm run ts-cli-install
$ ts-cli hello
Hello, World!
$ npm run hello Universe!
$ ts-cli hello Universe!
Hello, Universe!!
$ npm run calc -o multiply 10 16 # or: add | divide
$ ts-cli calc -o multiply 10 16 # or: add | divide
160
$ npm run age Ernie # Use axios to call the agify API
$ ts-cli age Ernie # Use axios to call the agify API
Ernie - 74
```
Loading

0 comments on commit b438302

Please sign in to comment.