Skip to content

Eliminate Jest's --forceExit by Identifying and Implementing Correct Firebase Client Library Teardown #9071

Open
@mkoval

Description

@mkoval

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:

  1. Set up a Jest test environment using Firebase Client SDK (e.g., for Firestore).
  2. Run tests using firebase emulators:exec "jest".
  3. 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) and terminate(db) are called successfully.
  • why-is-node-running (if used in globalTeardown) reports 0 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions