-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
- 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:
- Init a project using firebase init
- Set an actual project
- Create a bunch of docs on a single collection (I used 'affiliates')
- Make sure to use the real project name in initializeTestApp to allow triggers to run
- 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'});
});