Add test coverage report

pull/3/head
Amio 2018-07-18 14:11:11 +08:00
rodzic d371712afa
commit 4dfe3501b2
3 zmienionych plików z 14 dodań i 3 usunięć

1
.gitignore vendored
Wyświetl plik

@ -1 +1,2 @@
node_modules
.nyc_output

Wyświetl plik

@ -10,7 +10,7 @@
"bench": "node bench/index.js",
"preview": "node preview/serve.js",
"pretest": "npm run lint",
"test": "tap test/*.spec.js --reporter spec"
"test": "tap test/*.spec.js --reporter spec --100"
},
"devDependencies": {
"benchmark": "^2.1.4",

Wyświetl plik

@ -1,13 +1,23 @@
const tap = require('tap')
const calcWidth = require('../lib/calc-text-width.js').Verdana11
tap.test('calc width for "npm"', t => {
tap.test('basic functions', t => {
t.ok(typeof calcWidth === 'function', 'export calcWidth function')
t.ok(Number.isFinite(calcWidth('npm')), 'result is a number')
t.ok(Number.isFinite(calcWidth('')), 'result is a number')
t.ok(calcWidth('') === 0, 'return 0 for empty string')
t.end()
})
tap.test('calc width for "npm"', t => {
t.is(calcWidth('npm'), 24.9, 'result is correct value')
t.end()
})
tap.test('calc width for unicode', t => {
t.is(calcWidth('壹佰贰拾叁'), 55, 'result is correct value')
t.end()
})
tap.test('exception handling', t => {
t.throws(() => calcWidth(0), TypeError, 'throw if feed with non-string input')
t.end()