書籍「テスト駆動開発」を TypeScript で読み進めてみるレポジトリです。
事前に node.js はセットアップしているものとして。
$ npm init
...
$ npm install --save-dev typescript tslint mocha power-assert espower-typescript @types/node @types/mocha
...
test/sample.test.ts
import assert = require("assert");
import { say } from "../src/sample";
describe("#say()", () => {
it("Say, Hello world.", () => {
assert("Hello world." === say("world"));
});
});
src/sample.ts
export function say(message: string): string {
return "Hello " + message + ".";
}
$ npm test
> tdd-by-example-for-typescript@0.0.1 test /tdd-by-example-for-typescript
> mocha --require espower-typescript/guess test/**/*.ts
#say()
√ Say, Hello world.
1 passing (18ms)
$
A watch mode is:
$ npm run test:watch
> tdd-by-example-for-typescript@0.0.1 test /tdd-by-example-for-typescript
> mocha --watch-extensions ts -w --require espower-typescript/guess test/**/*.ts
#say()
√ Say, Hello world.
1 passing (18ms)
([Ctrl] + C)
$
+ dist/ : コンパイル後のコード(*.js)と source map ファイル(*.js.map)
| |
| + src/
| |
| + test/
|
+ src/ : 本体のコード(*.ts)
|
+ test/ : テストコード(*.test.ts)