UNPKG

2.04 kBMarkdownView Raw
1# TS-Mocha
2> Mocha thin wrapper that allows running TypeScript tests with TypeScript runtime (ts-node) to get rid of compilation complexity.
3> All Mocha features are available without any limitation.
4
5### Why?
6To setup Mocha with TypeScript you have to figure out how to integrate them to work together, it's not an easy task and require some advanced knowledge.
7This package handles for you this complexity and let you use ts-mocha just as regular mocha that will handle TypeScript `.ts` and `.tsx` files. Also added some usefull options, you can find them below.
8
9### How?
10TS-Mocha has one only dependency - ts-node, which is used as a TypeScript runtime to execute tests that can import and run imported TypeScript source files as well. It is as a thin wrapper that run local mocha package and set up ts-node environment to handle `.ts` and `.tsx` files. To speed up test execution of TypeScript code type-cheking is disabled, and it is using only transpile module.
11
12### __PRO TIP__: To make your developer experience better I recommend to run type-checking in a seperate process by starting TSC compiler (preferably in watch mode) in you terminal with --noEmit and --project flags.
13
14### __NOTE__: This package does not include Mocha - I have set Mocha as peer dependency on purpose, so I don't lock consumer to a specific Mocha version but most importantly, I don't have to update this package when Mocha is updated, and all the new features will be available automatically from your local Mocha package. Also integration with your existing Mocha setup is non-invasive.
15
16### Options:
17-p, --project Relative or absolute path to directory containing tsconfig (the same as `tsc -p <value>`) [default: "."]
18
19### Installation
20
21- Local:
22```
23# remember to install mocha if you don't have it already (npm i -D mocha)
24npm i -D ts-mocha
25`./node_modules/.bin/ts-mocha -p src/ src/**/*.spec.ts`
26```
27
28- Global:
29```
30# remember to install mocha if you don't have it already (npm i -g mocha)
31npm i -g ts-mocha
32`ts-mocha -p src/ src/**/*.spec.ts`
33```
\No newline at end of file