Skip to content

Instantly share code, notes, and snippets.

@kasecato
Last active July 19, 2020 05:52
Show Gist options
  • Save kasecato/7a3eefd3ec597be354e9 to your computer and use it in GitHub Desktop.
Save kasecato/7a3eefd3ec597be354e9 to your computer and use it in GitHub Desktop.
カバレッジが高いと品質が高い?Javascript / TypeScript のカバレッジを可視化して網羅する単体テストコード入門 ref: https://qiita.com/kasecato/items/1619b3e2c2e52c756736
{
"coverage": ["./coverage/lcov.info"],
"sourcemapped": ["./out/src/*/**.js"],
"automaticallyShow": true,
"ignore": ["*.json"]
}
git clone https://github.com/kasecato/tscodecover.git
cd tscodecover
npm install
npm run build
code .
git clone https://github.com/bmeck/vscode-code-cover.git
cd vscode-code-cover/example/
npm install
npm run build
npm run coverage
code .
npm run build
npm install
npm install
./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report none -- --ui tdd ./out/test/**/*.js
./node_modules/.bin/nyc --reporter=lcovonly -- ./node_modules/.bin/mocha --ui tdd ./out/test/**/*.js
npm run build
import * as assert from 'assert';
import {NumberUtil} from '../../src/util/NumberUtil';
suite('NumberUtil Tests', () => {
test('isOdd', () => {
// arrange
const n = 2501;
// act
const actual: boolean = NumberUtil.isOdd(n);
// assert
assert.equal(actual, true);
});
});
export class NumberUtil {
public static isOdd(n: number): boolean {
if (n === undefined) {
return false;
} else if (n % 2 === 1) {
return true;
}
return false;
}
}
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "coverage",
"group": "test"
}
]
}
tscodecover/
├── .eslintrc.json
├── coverageconfig.json
├── package.json
├── tsconfig.json
|
├── .vscode/
| └── tasks.json
├── coverage/
| ├── coverage.json
| └── lcov.info
├── src/
│ └── Util/
│ └── NumberUtil.ts
├── test/
│ └── Util/
│ └── NumberUtil.test.ts
└── out/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment