Had a quick question about using AVA for testing with Firebase. When using test.after.finally() with Firebase Admin to delete user accounts in test cleanup, the promise is not resolving or throwing an error. There's a very strong chance that I am not doing the correct thing here and would love some input.
My Code:
test.after.always(async () => {
internals.ids.forEach(async (id) => {
await admin.database().ref(`users/${id}`).remove();
await admin.auth().deleteUser(id);
});
});
Where internals.ids is an array of ids that need to be cleaned up at the end of running all of the tests.
This may or may not be related to the non-serial nature of AVA but I'm not 100% sure. If you need more information please let me know. Thanks!
Try this instead:
for (const id of internals.ids) {
await ...remove()
await ...deleteUser(id)
}
Because you're using forEach()
, the after hook isn't actually waiting for any of your removals / user deletions to complete, and the process likely hard exits before they do.