Ответ 1
Я сделал еще немного копания в mocha.js и, наконец, обнаружил, что mocha.run() фактически возвращает бегун, который испускает все события, которые я искал.
В исходном примере, который я использовал, был только: mocha.run()
Итак, если Mocha.run() возвращает бегун, я понял, что могу подписаться на него:
var runner = mocha.run();
var testsPassed = 0;
var onTestPassedHandler = function(e){
testsPassed++;
console.log("onTestPassedHandler - title: " + e.title + " - total:" + testsPassed);
};
runner.on("pass", onTestPassedHandler);
/**
* These are all the events you can subscribe to:
* - `start` execution started
* - `end` execution complete
* - `suite` (suite) test suite execution started
* - `suite end` (suite) all tests (and sub-suites) have finished
* - `test` (test) test execution started
* - `test end` (test) test completed
* - `hook` (hook) hook execution started
* - `hook end` (hook) hook complete
* - `pass` (test) test passed
* - `fail` (test, err) test failed
*/
намного лучше!