1 | # espower-typescript
|
2 |
|
3 | > power-assert instrumentor for TypeScript
|
4 |
|
5 | [![npm version][npm-image]][npm-url]
|
6 | ![Node.js Version Support][node-version]
|
7 | ![TypeScript Version Support][ts-version]
|
8 | [![build status][ci-image]][ci-url]
|
9 | [![Dependency Status][deps-image]][deps-url]
|
10 | ![monthly downloads][npm-downloads-image]
|
11 | ![License][license]
|
12 |
|
13 | ## TypeScript versions
|
14 |
|
15 | espower-typescript v10.x is compatible with TypeScript v2.7+
|
16 |
|
17 | ## Usage (zero-config mode)
|
18 |
|
19 | Install
|
20 |
|
21 | ```console
|
22 | $ npm install -D espower-typescript power-assert mocha typescript @types/node @types/mocha
|
23 | ```
|
24 |
|
25 | Create a test file (intensionally failed)
|
26 |
|
27 | ```typescript
|
28 | // test/test.ts
|
29 | import assert = require('assert');
|
30 |
|
31 | describe('Array#join', () => {
|
32 | it('joins all elements into a string with separator', () => {
|
33 | assert(['a', 'b', 'c'].join(':') === 'a:b:c:');
|
34 | });
|
35 | });
|
36 | ```
|
37 |
|
38 | Run test
|
39 |
|
40 | ```console
|
41 | $ ./node_modules/.bin/mocha --require espower-typescript/guess "test/**/*.ts"
|
42 | ```
|
43 |
|
44 | Output
|
45 |
|
46 | ```
|
47 | 1) Array#join
|
48 | joins all elements into a string with separator:
|
49 |
|
50 | AssertionError [ERR_ASSERTION]: # test.ts:6
|
51 |
|
52 | assert(['a','b','c'].join(':') === 'a:b:c:')
|
53 | | | |
|
54 | ["a","b","c"] "a:b:c" false
|
55 | ```
|
56 |
|
57 | ### CAUTION: don't use `import assert from 'assert'`
|
58 |
|
59 | Just use old style `import assert = require('assert')` for assert module.
|
60 | This is limitation.
|
61 |
|
62 | ## Configure
|
63 |
|
64 | ### If your tests are not in `test` directory
|
65 |
|
66 | You can set test directory in your `package.json`
|
67 |
|
68 | ```json
|
69 | {
|
70 | "name": "your-module",
|
71 | "description": "Your module",
|
72 | "version": "0.0.1",
|
73 | "directories": {
|
74 | "test": "spec/"
|
75 | },
|
76 | ...
|
77 | }
|
78 | ```
|
79 |
|
80 | Then, run mocha with `--require espower-typescript/guess`
|
81 |
|
82 | ```console
|
83 | $ ./node_modules/.bin/mocha --require espower-typescript/guess "spec/**/*.ts"
|
84 | ```
|
85 |
|
86 | Note: `'espower-typescript/guess'` is inspired by [intelli-espower-loader](https://github.com/azu/intelli-espower-loader)
|
87 |
|
88 | ### ts-node and `tsconfig.json`
|
89 |
|
90 | espower-typescript uses [ts-node](https://github.com/TypeStrong/ts-node) internally.
|
91 | It loads your [tsconfig.json](https://github.com/Microsoft/TypeScript/wiki/tsconfig.json) automatically.
|
92 |
|
93 | ### Disable type check (transpile only)
|
94 |
|
95 | Use `TS_NODE_TRANSPILE_ONLY` env of ts-node
|
96 |
|
97 | ```console
|
98 | $ TS_NODE_TRANSPILE_ONLY=1 ./node_modules/.bin/mocha --require espower-typescript/guess "test/**/*.ts"
|
99 | ```
|
100 |
|
101 | ### JSX/React
|
102 |
|
103 | `.tsx` files are supported.
|
104 |
|
105 | ### `allowJs`
|
106 |
|
107 | If `allowJs: true` in your `tsconfig.json`, assertions in `test/**/*.(js|jsx)` are empowered.
|
108 |
|
109 | ## License
|
110 |
|
111 | - MIT License: Teppei Sato <teppeis@gmail.com>
|
112 | - Includes [yosuke-furukawa/espower-traceur](https://github.com/yosuke-furukawa/espower-traceur)
|
113 | - Includes [azu/espower-babel](https://github.com/azu/espower-babel)
|
114 |
|
115 | [npm-image]: https://badgen.net/npm/v/espower-typescript?icon=npm&label=
|
116 | [npm-url]: https://npmjs.org/package/espower-typescript
|
117 | [npm-downloads-image]: https://badgen.net/npm/dm/espower-typescript
|
118 | [ci-image]: https://github.com/power-assert-js/espower-typescript/workflows/Node.js%20CI/badge.svg
|
119 | [ci-url]: https://github.com/power-assert-js/espower-typescript/actions?query=workflow%3A%22Node.js+CI%22
|
120 | [deps-image]: https://badgen.net/david/dep/power-assert-js/espower-typescript
|
121 | [deps-url]: https://david-dm.org/power-assert-js/espower-typescript
|
122 | [node-version]: https://badgen.net/npm/node/espower-typescript
|
123 | [ts-version]: https://badgen.net/badge/typescript/%3E=2.7?icon=typescript
|
124 | [license]: https://badgen.net/npm/license/espower-typescript
|