1 | # nyc-config-typescript
|
2 |
|
3 | Handy default configuration for instrumenting your TypeScript-backed
|
4 | project with test coverage using [nyc](https://github.com/istanbuljs/nyc).
|
5 |
|
6 | First install the dependencies:
|
7 |
|
8 | ```
|
9 | npm i -D nyc source-map-support ts-node @istanbuljs/nyc-config-typescript
|
10 | ```
|
11 |
|
12 | **Your `tsconfig.json` must be configured to produce source maps, either inline or as sibling files.**
|
13 |
|
14 | ## .nycrc
|
15 |
|
16 | And write a `.nycrc` that looks like this:
|
17 |
|
18 | ```js
|
19 | {
|
20 | "extends": "@istanbuljs/nyc-config-typescript",
|
21 | // OPTIONAL if you want coverage reported on every file, including those that aren't tested:
|
22 | "all": true
|
23 | }
|
24 | ```
|
25 |
|
26 | This package specifies the `cache`, `exclude`, and `extension` options for you - only override those if you absolutely must.
|
27 | If you are going to modify `include` or `exclude` and you have specified a separate `outDir` in `tsconfig.json`, make sure that it remains included so that source mapping is possible.
|
28 |
|
29 | ## Running Tests
|
30 |
|
31 | ### If you're using `mocha`
|
32 |
|
33 | In `test/mocha.opts`:
|
34 |
|
35 | ```
|
36 | --require ts-node/register #replace with ts-node/register/transpile-only if you have custom types
|
37 | --require source-map-support/register
|
38 | --recursive
|
39 | <glob for your test files>
|
40 | ```
|
41 |
|
42 | Now setup the test scripts in your `package.json` like so (with the equivalent for your test runner):
|
43 |
|
44 | ```json
|
45 | {
|
46 | "test": "tsc && nyc mocha"
|
47 | }
|
48 | ```
|
49 |
|
50 | ### If you're using Jasmine
|
51 | In `package.json`:
|
52 |
|
53 | ```json
|
54 | {
|
55 | "test": "tsc && nyc --require ts-node/register jasmine"
|
56 | }
|
57 | ```
|
58 |
|
59 | ## License
|
60 |
|
61 | ISC
|