power-assert instrumentor for TypeScript
espower-typescript v10.x is compatible with TypeScript v2.7+
Install
$ npm install -D espower-typescript power-assert mocha typescript @types/node @types/mocha
Create a test file (intensionally failed)
// test/test.ts
import assert = require('assert');
describe('Array#join', () => {
it('joins all elements into a string with separator', () => {
assert(['a', 'b', 'c'].join(':') === 'a:b:c:');
});
});
Run test
$ ./node_modules/.bin/mocha --require espower-typescript/guess "test/**/*.ts"
Output
1) Array#join
joins all elements into a string with separator:
AssertionError [ERR_ASSERTION]: # test.ts:6
assert(['a','b','c'].join(':') === 'a:b:c:')
| | |
["a","b","c"] "a:b:c" false
Just use old style import assert = require('assert')
for assert module.
This is limitation.
You can set test directory in your package.json
{
"name": "your-module",
"description": "Your module",
"version": "0.0.1",
"directories": {
"test": "spec/"
},
...
}
Then, run mocha with --require espower-typescript/guess
$ ./node_modules/.bin/mocha --require espower-typescript/guess "spec/**/*.ts"
Note: 'espower-typescript/guess'
is inspired by intelli-espower-loader
espower-typescript uses ts-node internally. It loads your tsconfig.json automatically.
Use TS_NODE_TRANSPILE_ONLY
env of ts-node
$ TS_NODE_TRANSPILE_ONLY=1 ./node_modules/.bin/mocha --require espower-typescript/guess "test/**/*.ts"
.tsx
files are supported.
If allowJs: true
in your tsconfig.json
, assertions in test/**/*.(js|jsx)
are empowered.
- MIT License: Teppei Sato <[email protected]>
- Includes yosuke-furukawa/espower-traceur
- Includes azu/espower-babel