Skip to content

Jest + @firebase/rules-unit-testing has unstopped asynchronous operations #4884

@Francesco-Lanciana

Description

@Francesco-Lanciana

[REQUIRED] Describe your environment

  • Operating System version: macOS Big Sur (Version 11.2.3)
  • Browser version: N/A
  • Firebase SDK version: 9.7.0
  • Firebase Product: firestore

[REQUIRED] Describe the problem

When using @firebase/rules-unit-testing and jest the tests will not exit cleanly and you will get the warning:
Jest did not exit one second after the test run has completed.. Deleting the apps after the tests have finished does not help.

Steps to reproduce:

  1. Run the firestore emulator using firebase emulators:start
  2. Make sure jest is installed (I'm using version 26.6.3). In my case I'm also using ts-jest and @types/jest to write my tests using typescript.
  3. Create a basic test that attempts to get a document from the Firestore DB
  4. Run the tests using the jest command and you will get the following warning:
Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

--detectOpenHandles does not help at all, it just hangs instead of exiting.
I tried to delete every app after each test in order to close any asynchronous calls but that also didn't help.

Relevant Code:

import * as firebase from "@firebase/rules-unit-testing";

describe("Security rules", () => {
    afterEach(async () => {
        await Promise.all(firebase.apps().map((app) => app.delete()));
    });

    it("Can read stuff", async () => {
        const app = firebase.initializeTestApp({ projectId: "whatever" });
        const db = app.firestore();
        const testDoc = db.collection("private").doc("a_doc");
        await firebase.assertFails(testDoc.get());
    });
});

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