Reputation: 9411
A typical MochaJS test, of course, includes before
and after
blocks where one can run a setup/teardown.
However, I would like to perform an additional teardown step after all test files are processed - to take into account any loose resources that individual teardowns may forget to delete.
How could I achieve that in MochaJS?
Upvotes: 3
Views: 1778
Reputation: 4960
Most recent Mocha's version (8.x) bring support for root hook plugin, which allow to do exactly what you need, if you running tests in serial mode. There is a good point to start: https://mochajs.org/#root-hook-plugins
Upvotes: 1
Reputation: 2531
You can run Mocha
programmatically. The nice thing is that Mocha support events for the runner that exposes exactly what you need.
mocha.run() returns a Runner instance which emits many events of interest.
* Events:
* - `start` execution started
* - `end` execution complete
...
Upvotes: 0