Open xtx1130 opened 6 years ago
跟大家分享一下如何使用travis-ci和coveralls.io分别实现持续集成和覆盖度测试报告上传
npm上包的储备量实在是太大了,如何快速找到你心仪的而且高质量的包呢?
travis-ci是一款开源的实现持续集成的工具。因为开源而且空间公用,所以比较适合个人开发者或者较小的项目(像node这种的都会有自己搭建的jekins,集成版本也会有很多版本,而且每天都会有nightly-build)。
这个使用起来也是非常方便的,你只需要在你的文件目录的根目录下加上.travis.yml文件,然后上传到git上就好了,tarvis-ci可以同步你github上的项目。接下来跟大家详细说一下常用的配置:
.travis.yml
sudo: false//sudo 最好设置成false,这样travis会对你的项目根据提交的集成时间顺延进行集成,而且官方不鼓励sudo language: node_js //语言设置,前端来说一般都是node咯 node_js: - "8"//集成时候用到的nodejs版本,如果是多个请继续在下面加 - "9",ps:不同版本会分开集成 install: npm install//在环境构建的时候执行的指令,一般都是npm install吧,装npm包 script: npm test // 这是在执行的时候运行的命令,执行一遍单测保证程序的可用性,如果有问题会直接exit 1退出 os: - linux //操作系统环境 after_script: npm run cov//在命令执行完之后运行的指令,在这里run cov是利用coveralls.io和jest实现覆盖度测试并把报告上传到coveralls.io env: global://设置集成环境的全局变量 - NODE_ENV=travis
下面给大家看一下 npm test 和npm run cov的指令分别是什么:
"scripts": { "test": "./node_modules/.bin/cross-env NODE_ENV=travis jest --forceExit", "cov": "./node_modules/.bin/cross-env NODE_ENV=travis npm run test -- --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", "debug": "nodemon ./index.js" }
coveralls.io 是一款开源的上传覆盖度测试报告的工具,并根据上传的报告形成coverage角标,你在上面也可以清晰地看到每次提交的报告的对比,以及每次提交的覆盖率的增长率。 根据这张图片可以看到,我提交了三次,覆盖度增长到了百分之百。
这个覆盖度测试报告使用起来也很简单,刚才的代码中也有使用方式了:
./node_modules/.bin/cross-env NODE_ENV=travis npm run test -- --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
在npm install comveralls --save-dev 之后,它会提供给你一个cli工具,通过调用这个工具,把lcov.info上传给coveralls.io,形成最终的测试报告。覆盖度测试一般用的包是istanbul,jest也不例外。它内部集成了istanbul,所以在需要忽略一些分支的时候,请使用istanbul的注释规则进行忽略。还有如果在单独使用istanbul进行覆盖度测试的时候,有一些es6语法不被支持,请先用babel转义或者利用babel-istanbul来进行覆盖度测试。
babel-istanbul
by 小菜
博主说自己是后厂村村草。我不服,大家同意的点赞
@For-me -,-
背景(npm找包指北)
npm上包的储备量实在是太大了,如何快速找到你心仪的而且高质量的包呢?
travis-ci简介和使用
简介
travis-ci是一款开源的实现持续集成的工具。因为开源而且空间公用,所以比较适合个人开发者或者较小的项目(像node这种的都会有自己搭建的jekins,集成版本也会有很多版本,而且每天都会有nightly-build)。
使用
这个使用起来也是非常方便的,你只需要在你的文件目录的根目录下加上
.travis.yml
文件,然后上传到git上就好了,tarvis-ci可以同步你github上的项目。接下来跟大家详细说一下常用的配置:下面给大家看一下 npm test 和npm run cov的指令分别是什么:
.travis.yml
进行一次集成。coveralls.io简介和使用
简介
coveralls.io 是一款开源的上传覆盖度测试报告的工具,并根据上传的报告形成coverage角标,你在上面也可以清晰地看到每次提交的报告的对比,以及每次提交的覆盖率的增长率。 根据这张图片可以看到,我提交了三次,覆盖度增长到了百分之百。
使用
这个覆盖度测试报告使用起来也很简单,刚才的代码中也有使用方式了:
在npm install comveralls --save-dev 之后,它会提供给你一个cli工具,通过调用这个工具,把lcov.info上传给coveralls.io,形成最终的测试报告。覆盖度测试一般用的包是istanbul,jest也不例外。它内部集成了istanbul,所以在需要忽略一些分支的时候,请使用istanbul的注释规则进行忽略。还有如果在单独使用istanbul进行覆盖度测试的时候,有一些es6语法不被支持,请先用babel转义或者利用
babel-istanbul
来进行覆盖度测试。by 小菜