1 | # ts-node-test-register [](https://github.com/azu/ts-node-test-register/actions?query=workflow%3A"test")
|
2 |
|
3 | Use `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 |
|
9 | This 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 |
|
18 | You 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 |
|
28 | In some times, we use different `tsconfig.json` between main code and test code.
|
29 |
|
30 | For example, you can enable `allowJs` in test code.
|
31 | It 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 "Fast" By Default · TypeStrong/ts-node")
|
38 |
|
39 | The 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 |
|
44 | This 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 |
|
52 | Install 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").
|
57 | You need to install `ts-node`.
|
58 |
|
59 | ## Usage
|
60 |
|
61 | Using with [mocha](https://github.com/mochajs/mocha "mocha").
|
62 |
|
63 | ```
|
64 | mocha --require ts-node-test-register "test/**/*.ts"
|
65 | ```
|
66 |
|
67 | Or 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 |
|
79 | For more details, see [example](./example/).
|
80 |
|
81 | ## Changelog
|
82 |
|
83 | See [Releases page](https://github.com/azu/ts-node-test-register/releases).
|
84 |
|
85 | ## Running tests
|
86 |
|
87 | Install devDependencies and Run `yarn test`:
|
88 |
|
89 | yarn test
|
90 | yarn run test:example
|
91 |
|
92 | ## Contributing
|
93 |
|
94 | Pull requests and stars are always welcome.
|
95 |
|
96 | For bugs and feature requests, [please create an issue](https://github.com/azu/ts-node-test-register/issues).
|
97 |
|
98 | 1. Fork it!
|
99 | 2. Create your feature branch: `git checkout -b my-new-feature`
|
100 | 3. Commit your changes: `git commit -am 'Add some feature'`
|
101 | 4. Push to the branch: `git push origin my-new-feature`
|
102 | 5. 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 |
|
111 | MIT © azu
|