UNPKG

1.48 kBMarkdownView Raw
1# nyc-config-typescript
2
3Handy default configuration for instrumenting your TypeScript-backed
4project with test coverage using [nyc](https://github.com/istanbuljs/nyc).
5
6First install the dependencies:
7
8```
9npm 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
16And 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
26This package specifies the `cache`, `exclude`, and `extension` options for you - only override those if you absolutely must.
27If 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
33In `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
42Now 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
51In `package.json`:
52
53```json
54{
55 "test": "tsc && nyc --require ts-node/register jasmine"
56}
57```
58
59## License
60
61ISC