1.3 gulp-mocha和mochawesome

该博客介绍了如何结合gulp任务管理器和mocha测试框架来运行JavaScript测试。通过配置gulpfile.js,设置mocha选项如reporter为mochawesome,可以生成详细的测试报告。mochawesome提供了如quiet、reportFilename等参数来自定义报告。执行'gulp default'命令即可执行测试并产出测试报告,这对于持续集成环境中的测试结果展示非常有用。

一、gulp官方文档

https://v3.gulpjs.com.cn/docs/recipes/mocha-test-runner-with-gulp/

var gulp = require('gulp');
var mocha = require('gulp-mocha');

gulp.task('default', function() {
  return gulp.src(['test/test-*.js'], { read: false })
    .pipe(mocha({
      reporter: 'spec',
      globals: {
        should: require('should')
      }
    }));
});

二、执行gulp default命令,便可执行mocha测试

三、gulp-mocha

gulp-mocha提供了mocha(options?)方法,options是一个对象

如下摘抄部分参数,详细参考https://www.npmjs.com/package/gulp-mocha/v/8.0.0

其中reporter参数可以配置mochawesome

ui

Type: string
Default: bdd
Values: bdd tdd qunit exports

Interface to use.

reporter

Type: string
Default: spec Values: Reporters

Reporter that will be used.

This option can also be used to utilize third-party reporters. For example, if you npm install mocha-lcov-reporter you can then do use mocha-lcov-reporter as value.

reporterOptions

Type: object
Example: {reportFilename: 'index.html'}

Reporter specific options.

 四、mochawesome

文档地址:https://www.npmjs.com/package/mochawesome

var mocha = new Mocha({
  reporter: 'mochawesome',
  reporterOptions: {
    reportFilename: 'customReportFilename',
    quiet: true,
  },
});

 mochawesome的主要参数

Option NameTypeDefaultDescription
quietbooleanfalseSilence console messages
reportFilenamestringmochawesomeFilename of saved report
Applies to the generated html and json files.
htmlbooleantrueSave the HTML output for the test run
jsonbooleantrueSave the JSON output for the test run
consoleReporterstringspecName of mocha reporter to use for console output, or none to disable console report output entirely

配置mochawesome后,执行gulp default,将会生成测试报告,在服务器的持续集成中,可以将测试报告部署到tomcat服务器下,实现在线查看

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值