Skip to content

withFunctionTriggersDisabled from @firebase/rules-unit-testing fails with timeout if there is no internet connection #8022

Open
@sceee

Description

@sceee

Operating System

Windows

Browser Version

Firebase SDK Version

10.8.0

Firebase SDK Product:

Firestore

Describe your project's tooling

Node JS Cloud Functions accessing firestore

Describe the problem

When using the emulator suite and using @firebase/rules-unit-testing to test Firestore rules, as soon as I add the following code in an after hook in the tests and execute the tests while being offline, they fail with a timeout:

...
  let adminDb: Firestore
  let firebaseTestEnvironment: RulesTestEnvironment
  let userDB: firebaseJSCompat.firestore.Firestore

before(async () => {
    adminDb = getFirestore()

    const rulesContent = fs.readFileSync(path.resolve(__dirname, '../../../firestore.rules'), 'utf8')

    firebaseTestEnvironment = await initializeTestEnvironment({
          projectId: TEST_FIREBASE_PROJECT_ID,
          firestore: {
            rules: rulesContent,
          },
        })

    userDB = firebaseTestEnvironment
            .authenticatedContext("123", {
              email: `[email protected]`,
            })
            .firestore()
  })

it('tests something', async () => {
          await assertSucceeds(inexistentUserDB.collection("whatever").doc("abc").get())
})
...

after(async () => {
  await resetData()
})

async function resetData(): Promise<void> {
  await withFunctionTriggersDisabled(async () => {
    // For testing purposes we do nothing here as it doesn't matter
    await Promise.resolve()
  })
}

The error logged is:

"after all" hook for "tests something":
Error: Timeout of 15000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

When getting back online without changing any code, everything passes and there is no timeout.
The same happens if the withFunctionTriggersDisabled is removed.

The tests are executed using

firebase emulators:exec --import=./test/emulatordata \"npm test\"

npm test is mocha --reporter spec --timeout 15000.

Steps and code to reproduce issue

See above.

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