Description
Issue Description:
When using the Firebase Client SDK with Jest and firebase emulators:exec
, Jest fails to exit cleanly without the --forceExit
flag, even when deleteApp()
and terminate()
are called in globalTeardown
. This necessitates the use of --forceExit
, which is undesirable as it can mask other potential issues.
Steps to Reproduce:
- Set up a Jest test environment using Firebase Client SDK (e.g., for Firestore).
- Run tests using
firebase emulators:exec "jest"
. - Implement
jest.globalTeardown.js
with:const { deleteApp } = require('firebase/app'); const { terminate } = require('firebase/firestore'); const { app, db } = require('./src/firebase'); // Assuming app and db are exported module.exports = async () => { if (app) { await deleteApp(app); } if (db) { await terminate(db); } };
Observed Behavior:
deleteApp(app)
andterminate(db)
are called successfully.why-is-node-running
(if used inglobalTeardown
) reports0 handle(s) keeping the process running
.- Jest issues a warning: "Jest did not exit one second after the test run has completed."
- There is a noticeable delay between Jest completing its tests and
firebase emulators:exec
initiating emulator shutdown. - Using
--forceExit
in the Jest command makes Jest exit and suppresses the warning.
Expected Behavior:
The Firebase client library should provide teardown mechanisms (deleteApp
, terminate
, or others if necessary) that allow Jest to exit cleanly and promptly on its own, without requiring --forceExit
. The Node.js process should terminate naturally after all Firebase resources are released.
Request:
Please provide guidance on how to tear down the Firebase SDK in a test environment, without requiring the test framework to forcefully exiting the process.