在Mocha浏览器中使用多个记者?

Sco*_*oss 6 javascript testing mocha.js

是否可以在浏览器版本的Mocha中使用多个记者?我正在创建一个将测试结果发送到我的服务器的记者,但我仍然想使用默认的HTML记者Mocha默认值.现在我正在修改源代码以使其工作.我知道Mocha也为它的记者使用commonJS.

Tha*_*hai 3

mocha.run返回一个 runner 对象,该对象发出有用的事件,例如'test end''suite end'。因此,我们可以这样做:

mocha.run()
.on('test end', function(test) {
  if ('passed' === test.state) {
    console.log('passed!', test.title)
  } else if (test.pending) {
    console.log('pending!', test.title)
  } else {
    console.log('fail!', test.title)
    let err = test.err
    console.log(err)
  }
  // logic to collect results
})
.on('suite end', function(suite) {
  if (suite.root) {
    // logic to send collected results to server
  }
})
Run Code Online (Sandbox Code Playgroud)