protractor - 如何在具有多报告器的量角器中使用 mocha 自定义报告器
问题描述
我想使用带有 mocha-json、https: //mochajs.org/#json 的自定义报告器,并将其包含在我的量角器配置文件中。我创建了一个报告文件,并通过 npm 模块安装它。我把它mochaOpts
作为mocha-multi-reporter
. 但是在运行测试时,我没有从记者那里得到任何结果或控制台日志。
conf.shared.ts
var mochaJsonReporter = new Mocha({
reporter: './node_modules/mocha-json-reporter'
});
mochaOpts: {
reporter: 'mocha-multi-reporters',
reporterOptions: {
reporterEnabled:
'mocha-junit-reporter, mocha-json-reporter',
mochaJunitReporterReporterOptions: {
mochaFile: './reports/junit/junit.xml'
},
mochaJsonReporterOptions: {
// what to include here?
},
Reporter.js - 发布为 npm 包 - mocha-json-reporter
'use strict';
/**
* @module JSON
*/
/**
* Module dependencies.
*/
var Base = require('./base');
/**
* Expose `JSON`.
*/
exports = module.exports = JSONReporter;
/**
* Initialize a new `JSON` reporter.
*
* @public
* @class JSON
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @api public
* @param {Runner} runner
*/
function JSONReporter(runner) {
Base.call(this, runner);
var self = this;
var tests = [];
var pending = [];
var failures = [];
var passes = [];
runner.on('test end', function(test) {
console.log('end ---- ', test.title);
tests.push(test);
});
runner.on('pass', function(test) {
console.log('pass ---- ', test.title);
passes.push(test);
});
runner.on('fail', function(test, err) {
console.log('fail ---- ', test.title, err.message);
failures.push(test);
});
runner.on('pending', function(test) {
console.log('pending --- ', test.title);
pending.push(test);
});
runner.once('end', function() {
var obj = {
stats: self.stats,
tests: tests.map(clean),
pending: pending.map(clean),
failures: failures.map(clean),
passes: passes.map(clean)
};
runner.testResults = obj;
process.stdout.write(JSON.stringify(obj, null, 2));
});
}
解决方案
推荐阅读
- react-native - 经常在带有 shadow-cljs 和 React Native 的 Cider 中看到“REPL 命令超时”。必须重启模拟器才能修复
- html - 为什么图像离开页面,而没有其他内容
- python - 如何在 tkinter 画布上绘制网格
- python - 为什么数据框在使用字符串的dtype时继续以整数形式读取文件
- javascript - 如何从 html 文件中获取控制器中 $scope.foo 的值
- android - 当点击通知应用程序不运行 Android [Xamarin.Forms] 中的 MainActivity
- python - 值错误没有足够的值来解压
- java - 从 for 循环内的二维数组中删除行后索引超出范围
- http - 仅在 IE/Edge 中看到的 Http 401
- javascript - 传单反应中的 openPopup 出错