我想使用带有自变量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));
});
}