visionmedia/mocha — pull request #1043 by Rulikkk (2013-11-19 22:50:52+00:00)
Title: Hook error handling (#534) -- continue testing even if some hooks are failing

This closes #534 and also affects #973, #975 and maybe #516, #581, #664, etc.

I have implemented hook-error behaviour in a try-finally manner, which means that for the failing hook, its counterpart will be executed (if exists), but the tests will be ignored, and the execution will skip to the next sibling suite.

In detail:

- If before hook fails, tests in a suite (where the hook is) and sub-suites are not executed. If after hook exists, it is called.
- If before each hook fails, remaining tests in that suite (where the hook is) or sub-suites are not executed. The remaining before hooks are also not executed. If after each hooks exist in that suite, or parent suites -- they get executed. The suite's after hooks are also executed.
- If after hook fails, no additional hooks are called.
- If after each hook fails, remaining tests in that suite (where the hook is) and sub-suites are not executed. The remaining after hooks (from parent suites) are executed. After hooks are executed 'up' starting from the suite of the last executed test, finishing with a suite where the hook is (inclusively).

After any hook error, the next sibling suite (relative to the suite with hook error) is executed.

This allows writing test hooks in a symmetrical manner:

- before (each): allocate all resources for this and child test suites or tests
- after (each): free all resources, allocated by before (each). Make sure, this will work correctly, even if some resource allocation failed -- it will still be called.