記事 is 何
テストをしたい。しよう。そう思って色々調べたメモ
取り敢えず package.json
に入っているものを入れて、 src
配下に ***.ts
で書く。
test配下にテストコードを書く。
npm run build
で変換する。
npm run test
でテストを動かして
npm run coverage
でテストカバレッジを測定する
ディレクトリ構成
.
├── .gitignore
├── README.md
├── package.json
├── src
│ └── sample.ts
├── test
│ └── sample.test.ts
├── tsconfig.json
└── tslint.json
最終的にこんな感じ
package.json
package.json
{
"name": "unit-test-sample",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha ./build/test/*.test.js",
"coverage": "istanbul cover _mocha -- ./build/test/*.test.js",
"build": "rm -rf ./build/* && tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/mocha": "^2.2.48",
"chai": "^4.1.2",
"istanbul": "^0.4.5",
"mocha": "^5.0.0",
"postinstall-build": "^5.0.1",
"remap-istanbul": "^0.10.1",
"tslint": "^5.9.1",
"tslint-config-airbnb": "^5.5.0",
"tsutils": "^2.21.0",
"typemoq": "^2.1.0",
"typescript": "^2.7.1"
}
}
tsconfig.json
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"outDir": "./build"
},
"include": [
"src/*",
"test/*"
],
"exclude": [
"node_modules"
]
}
tslint.json
{
"extends": "tslint-config-airbnb"
}
参考
ちゃんとテストしていきたい。