My package.json file contains the following:
...
"jest": "jest --runInBand",
"test": "firebase emulators:exec 'npm run jest'"
...
which allows me to run tests based on jest with a running Firebase Emulator.
Consider the following piece of code:
describe("MyTests", () => {
const req = supertest(app);
let user: admin.auth.UserRecord;
let idToken: string | undefined;
beforeAll(async () => {
const email = "test@gmail.com";
const password = "password";
user = await admin.auth().createUser({ email: email, password: password });
await auth.signInWithEmailAndPassword(email, password);
idToken = await auth.currentUser?.getIdToken();
});
// actual tests
Where I'm creating a Firebase user, which in turn trigger a function (functions.auth.user().onCreate(foo)).
I do notice that this foo function is being executed after the jest test suite is running:
Test Suites: 1 passed, 1 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 14.841 s, estimated 16 s
Ran all test suites.
ā Script exited successfully (code 0)
i functions: Beginning execution of "us-central1-foo"
i emulators: Shutting down emulators.
i functions: Stopping Functions Emulator
i functions: Waiting for all functions to finish...
i functions: Finished "us-central1-foo" in ~1s
How can I wait for it to be executed from inside the beforeAll() function?