It seems like if I try and do something asynchronous (or just slow?) from an always.afterEach()
function the process won't wait for it to complete when the test fails. My specific case if is that I'm trying to do some database cleanup after each test and even though the afterEach
hook gets called it doesn't seem to be given a chance to finish before the process exits.
I've tried to distill this down to a simple example:
import test from 'ava'
test.afterEach.always('CLEANUP', async t => {
console.log('START', t.title)
await new Promise(resolve => setTimeout(resolve, 5000))
console.log('END', t.title)
})
test('Test', async t => {
console.log('START', t.title)
t.plan(1)
t.is(1, 2)
console.log('END', t.title)
})
This is the output I get:
START Test
END Test
✖ Test 1 === 2
START CLEANUP for Test
1 test failed [10:42:18]
1. Test
AssertionError: 1 === 2
_callee2$ (cleanup-test.js:15:5)
Test.fn (cleanup-test.js:11:1)
I would expect to see END CLEANUP
printed (that does happen when the test passes.
I'm new to server-side JS so I'm hoping that I'm just doing something silly.
UPDATE: It turns out that this only breaks when the fails-fast flag is set. That's probably a bug.