After a quick check of the code, I believe that for the code in afterthere is no access to the video or reporters. However, there is a way to get the state of the tests at run time:
describe("blah", function () {
it("blah", function () {
throw new Error("blah");
});
after(function (){
var failed = false;
var tests = this.test.parent.tests;
for(var i = 0, limit = tests.length; !failed && i < limit; ++i)
failed = tests[i].state === "failed";
if (failed)
console.log("FAILED");
});
});
var tests = this.test.parent.tests. , this.test , after. this.test.parent - , describe. this.test.parent.tests - . , , "failed".
, , ( ). , Mocha .
, , , , . , , ( has_failed):
var hook_failure = false;
function make_wrapper(f) {
return function wrapper() {
try {
f.apply(this, arguments);
}
catch (e) {
hook_failure = true;
throw e;
}
};
}
function has_failed(it) {
var failed = false;
var tests = it.test.parent.tests;
for(var i = 0, limit = tests.length; !failed && i < limit; ++i)
failed = tests[i].state === "failed";
return failed;
}
describe("blah", function () {
before(make_wrapper(function () {
throw new Error("yikes!");
}));
it("blah", function () {
throw new Error("q");
});
after(function (){
var failed = has_failed(this);
if (failed)
console.log(this.test.parent.title + " FAILED");
});
});
after(function () {
if (hook_failure)
console.log("HOOK FAILURE");
});
after. , .