一、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:bddtddqunitexportsInterface to use.
reporter
Type:
string
Default:specValues: ReportersReporter that will be used.
This option can also be used to utilize third-party reporters. For example, if you
npm install mocha-lcov-reporteryou can then do usemocha-lcov-reporteras 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 Name | Type | Default | Description |
|---|---|---|---|
quiet | boolean | false | Silence console messages |
reportFilename | string | mochawesome | Filename of saved report Applies to the generated html and json files. |
html | boolean | true | Save the HTML output for the test run |
json | boolean | true | Save the JSON output for the test run |
consoleReporter | string | spec | Name of mocha reporter to use for console output, or none to disable console report output entirely |
配置mochawesome后,执行gulp default,将会生成测试报告,在服务器的持续集成中,可以将测试报告部署到tomcat服务器下,实现在线查看
该博客介绍了如何结合gulp任务管理器和mocha测试框架来运行JavaScript测试。通过配置gulpfile.js,设置mocha选项如reporter为mochawesome,可以生成详细的测试报告。mochawesome提供了如quiet、reportFilename等参数来自定义报告。执行'gulp default'命令即可执行测试并产出测试报告,这对于持续集成环境中的测试结果展示非常有用。
484

被折叠的 条评论
为什么被折叠?



