UNPKG

3.68 kBMarkdownView Raw
1# ts-node-test-register [![Actions Status: test](https://github.com/azu/ts-node-test-register/workflows/test/badge.svg)](https://github.com/azu/ts-node-test-register/actions?query=workflow%3A"test")
2
3Use `test/tsconfig.json` with [ts-node](https://github.com/TypeStrong/ts-node "ts-node") for testing.
4
5## Features
6
7### Load `test/tsconfig.json`
8
9This register library load `tsconfig.json` file by following priority.
10
11- `project/{test}/tsconfig.test.json`
12- `project/{test}/tsconfig.json`
13- `project/tsconfig.test.json`
14- `project/tsconfig.json`
15
16`{test}` is `test` directory by default.
17
18You can specified the `{test}` by `directories` of `package.json`.
19
20```
21 "directories": {
22 "test": "test"
23 },
24```
25
26**Notes:** Why need to load different `tsconfig.json` between main and test?
27
28In some times, we use different `tsconfig.json` between main code and test code.
29
30For example, you can enable `allowJs` in test code.
31It supports gradual migration that convert JavaScript to TypeScript.
32
33### Type Check by default
34
35<del>`ts-node`(v4) disable `type-check` by default.</del><ins>This behavior is reverted in [v6.0.0](https://github.com/TypeStrong/ts-node/releases/tag/v6.0.0)</ins>
36
37- [Release "Fast" By Default · TypeStrong/ts-node](https://github.com/TypeStrong/ts-node/releases/tag/v4.0.0 "Release &#34;Fast&#34; By Default · TypeStrong/ts-node")
38
39The motivation is based on so not good experience.
40
41- [Type error reporting · Issue #79 · kulshekhar/ts-jest](https://github.com/kulshekhar/ts-jest/issues/79 "Type error reporting · Issue #79 · kulshekhar/ts-jest")
42- [test(textlint-formatter): `mocha` runs fine while `tsc` cannot compile the script · Issue #448 · textlint/textlint](https://github.com/textlint/textlint/issues/448 "test(textlint-formatter): `mocha` runs fine while `tsc` cannot compile the script · Issue #448 · textlint/textlint")
43
44This register library supports [Mike Haas](https://github.com/mikehaas763 "Mike Haas")'s opinion.
45
46> test code is still code, if there's type errors in such test code, shouldn't it fail?
47> -- <https://github.com/kulshekhar/ts-jest/issues/79#issuecomment-355397865>
48
49
50## Install
51
52Install with [npm](https://www.npmjs.com/):
53
54 npm install ts-node ts-node-test-register --save-dev
55
56:warning: [ts-node](https://github.com/TypeStrong/ts-node "ts-node") is [peerDependencies](https://docs.npmjs.com/files/package.json#peerdependencies "peerDependencies").
57You need to install `ts-node`.
58
59## Usage
60
61Using with [mocha](https://github.com/mochajs/mocha "mocha").
62
63```
64mocha --require ts-node-test-register "test/**/*.ts"
65```
66
67Or define `--require ts-node-test-register` to [`.mocharc.{js,json,yml}`](example/.mocharc.json).
68
69```
70├── package.json
71├── .mocharc.json (--require ts-node-test-register)
72├── src
73│   └── index.ts
74└── test
75    ├── tsconfig.json // <= load this tsconfig.json
76    └── index-test.ts
77```
78
79For more details, see [example](./example/).
80
81## Changelog
82
83See [Releases page](https://github.com/azu/ts-node-test-register/releases).
84
85## Running tests
86
87Install devDependencies and Run `yarn test`:
88
89 yarn test
90 yarn run test:example
91
92## Contributing
93
94Pull requests and stars are always welcome.
95
96For bugs and feature requests, [please create an issue](https://github.com/azu/ts-node-test-register/issues).
97
981. Fork it!
992. Create your feature branch: `git checkout -b my-new-feature`
1003. Commit your changes: `git commit -am 'Add some feature'`
1014. Push to the branch: `git push origin my-new-feature`
1025. Submit a pull request :D
103
104## Author
105
106- [github/azu](https://github.com/azu)
107- [twitter/azu_re](https://twitter.com/azu_re)
108
109## License
110
111MIT © azu