Skip to content

The new feature withFunctionTriggersDisabled not really disable the triggers #2857

@hexetia

Description

@hexetia
  • Operating System version: Linux / Ubuntu 20.04
  • Browser version: Node 12
  • Firebase SDK version: 8.0.2, @firebase/rules-unit-testing: 1.1.1, firebase-admin: 9.4.0
  • Firebase Product: functions

The problem

Firebase 8.0.1 comes with a testing feature to disable functions triggers in emulator, I tried to use that new feature to clear Firestore data without triggering some triggers to make my tests more reliable, but that not worked, the triggers are called even wrapping custom firestore queries to delete the data manually

Steps to reproduce:

  1. Init a project using firebase init
  2. Set an actual project
  3. Create a bunch of docs on a single collection (I used 'affiliates')
  4. Make sure to use the real project name in initializeTestApp to allow triggers to run
  5. After wrapping the clearFirestore code make the code wait some seconds the allow triggers to run

Repository with test

https://github.com/saculbr/disableTriggersIssue

Relevant Code:

test('disable triggers test', async () => {
    await firebase.withFunctionTriggersDisabled(async () => {
        return await firebase.clearFirestoreData({ projectId: APP_ID });
    });

     // sleep three seconds to allow triggers to run
     await sleep(3000);

     const doc = await db.collection('bar').doc('bar').get();
     expect(doc.data()).toBeUndefined()
}, 10000); // increase test timeout
export const onDeleteAffiliate = functions
    .firestore.document(`affiliates/{affiliateId}`)
    .onDelete(async (docSnap, context) => {
        await sleep(100);
        await db.collection('bar').doc('bar').set({bar: 'bar'});
    });

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions