莫查声纳记者
Mocha 的 SonarQube XML 记者
特征 :
- 生成兼容的 xml 报表 声纳Qube
- 同时写入 stdout 的能力
- 为 stdout 定义自定义记者的能力
- 禁用输出的静态模式
- 自定义输出文件路径和/或名称
关于
我们需要能够生成xml报告供单位测试,然后导入到 声纳Qube。有几个图书馆试图帮助它,但是它们要么已经过时,生成了不相容的xml,要么只登录了xml来进行tdout。 此库将允许您以兼容的格式生成单位测试执行报告 普通测试格式 把它们写成文件 也可以向二级记者输送输出,用于人类可读视图.
使用量
添加摩卡- sonar 作为您的应用程序的依赖, 通过 npm 安装
npm install @danmasta/mocha-sonar --save-dev
使用记者进行测试
mocha -R @danmasta/mocha-sonar tests
选项
选项可用 reporterOptions 字段,或 --reporter-options 字段通过命令行
| 名称 | 说明 |
|---|---|
cwd | 用于生成用于测试的相对文件路径的位置 。 默认是 process.cwd() |
output | 您想要保存声纳 xml 报告的文件路径 。 默认是 ./coverage/sonar.xml |
delimiter | 用于合并名字用于巢穴测试的限定器 。 默认是 ' ' |
reporter | 您想要用于控制台输出的记者姓名 。 默认是 list |
silent | 若为 true 禁用二次报告输出。 默认是 false |
spaces | 格式化 xml 输出时要使用的空格数 。 默认是 4 |
实例
从命令行使用摩卡- 声纳
mocha -R @danmasta/mocha-sonar ./tests/unit/**/*.js
传递选项到 npm 测试命令
npm run test -- --reporter=@danmasta/mocha-sonar --reporter-options --reporter=nyan,delimeter=::
覆盖面报告 无
nyc --reporter=lcov mocha -R @danmasta/mocha-sonar ./tests/unit/**/*.js
使用摩卡和/或尼克作为 ulp 任务
const spawn = require('child_process').spawn;
const gulp = require('gulp');
gulp.task('test', () => {
return spawn('mocha -R @danmasta/mocha-sonar ./tests/unit/**/*.js', {
shell: true,
stdio: ['inherit', 'inherit', 'inherit']
});
});
gulp.task('coverage', () => {
return spawn('nyc --reporter=lcov mocha -R @danmasta/mocha-sonar ./tests/unit/**/*.js', {
shell: true,
stdio: ['inherit', 'inherit', 'inherit']
});
});
gulp.task('default', gulp.series('test', 'build'));
gulp.task('publish', gulp.series('coverage', 'build', 'deploy'));
联系人
有问题可以联系