Open
Description
See: #918 (comment)
after.always
has some issues when used as a cleanup task. Specifically, it won't run if:
- There are test failures and
--fail-fast
is used. - There are uncaught exceptions thrown.
I've advocated using .before
or .beforeEach
to ensure state is clean before running, but that means state is left on disk after the test run. It's easy enough to get around that:
function cleanup() {
if (temDirExists()) {
removeTempDir();
}
}
test.before(cleanup);
test.after.always(cleanup);
Still, it might be nicer if we had a modifier that allowed you to do it a little cleaner:
// runs as before and after
test.cleanup(cleanupFn);
// runs as beforeEach and after (not sure afterEach makes much sense?)
test.cleanupEach(cleanupFn);
Or maybe we introduce a .and
modifier:
test.before.and.after(cleanupFn);
test.beforeEach.and.after(cleanupFn);
test.beforeEach.and.afterEach(cleanupFn);
I think the second gives you a little more flexibility and is clearer without reading the docs. The first is probably simpler to implement (though I don't think the second would be very hard)
There is a $82.00 open bounty on this issue. Add more on Issuehunt.
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.