1.0.0 • Published 9 months ago

kigo-bin v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

安装

$ cnpm i kigo-bin --save-dev

用法

Add melot-bin to package.json scripts:

{
  "scripts": {
    "test-local": "melot-bin test",
    "test": "npm run lint -- --fix && npm run test-local",
    "cov": "melot-bin cov",
    "lint": "eslint ."
  }
}

测试

使用 mocha 和co-mocha 运行测试 断言库采用 power-assert

$ melot-bin test [files] [options]
  • files 默认为 test/**/*.test.js
  • test/fixtures, test/node_modules 自动被排除在测试用例之外

自动加载 test/.setup.js

如果 test/.setup.js 存在 首先运行这个文件中的内容

test
  ├── .setup.js
  └── foo.test.js

options

可以传递 mocha的参数 例如:

  • --require require the given module
  • --grep only run tests matching
  • --timeout milliseconds, default to 30000
  • --full-trace display the full stack trace, default to false.
  • 更多参数 https://mochajs.org/#usage

环境变量

支持环境变量设置测试参数

设置TESTS 环境变量 指定测试文件 支持通配符

TESTS=test/a.test.js melot-bin test

设置 TEST_REPORTER 设置报告格式, 默认格式为 spec.

TEST_REPORTER=doc melot-bin test

设置 TEST_TIMEOUT 指定测试用例超时时间, 默认30*1000ms.

TEST_TIMEOUT=2000 melot-bin test

测试覆盖率统计

  • 行覆盖率(line coverage):是否每一行都执行了?
  • 函数覆盖率(function coverage):是否每个函数都调用了?
  • 分支覆盖率(branch coverage):是否每个if代码块都执行了?
  • 语句覆盖率(statement coverage):是否每个语句都执行了?

  • 使用 istanbul 作为测试工具

  • 内置了 nyc 来支持单元测试自动生成代码覆盖率报告
  • 运行 npm run cov 执行测试
  • 报告生成在 coverage/lcov-report/index.html

忽略指定文件

1 npm run cov -- --x=app/plugins/*

2 设置环境变量 COV_EXCLUDES 设置忽略测试的文件

$ COV_EXCLUDES="app/plugins/c*,app/autocreate/**" melot-bin cov

忽略某些代码

1 var object = parameter || / istanbul ignore next / {};

2 / istanbul ignore if / if (hardToReproduceError)) { return callback(hardToReproduceError); }

License

MIT

[mocha]: https://mochajs.org
[co-mocha]: https://npmjs.com/co-mocha
[glob]: https://github.com/isaacs/node-glob
[istanbul]: https://github.com/gotwarlost/istanbul
[intelli-espower-loader]: https://github.com/power-assert-js/intelli-espower-loader
[power-assert]: https://github.com/power-assert-js/power-assert
[common-bin]: https://github.com/node-modules/common-bin
[sinon]: http://sinonjs.org/releases/v3.2.1/