Testing Firebase DAO layer without executing emulated Firestore triggers

Viewed 85

Goal

Trying to disable Firestore triggers "the proper way" for testing DAO layer.

Context

Hello !

I'm currently working on a tests-writing task for a Firebase project's back-end.
I wrote a test for my "DAO-layer method that get all collection's documents" (let's call it 'getCollection'), without any mock.

Stack

Back-end code is service-based, wrote in TypeScript.
Tests are made with mocha, also wrote in TypeScript, and run under Firebase emulators.

Expected

Test works perfectly AND no Firestore trigger is executed.

Actual result

Test works perfectly BUT concerned Firestore triggers are executed.

Researches

I found the withFunctionTriggersDisabled function from package @firebase/rules-unit-testing but it doesn't let me build JS (because of package @firebase/util doesn't exporting some things, probably because I DON'T have installed 'firebase' in my functions package.json)

Questions

  • Am I wrong to think the package @firebase/rules-unit-testing is a "front-end" thing ?
    I mean, if I'm correct, it comes from firebase package but firebase package is the front-end one (versus firebase-admin for back-end), no ?
    So what about using it for "back-end" tests ?
    It seems wrong to me to npm install firebase in "functions" directory while root's /package.json already have it.

All of this makes me think my testing env is not "properly" setup. :/

In fact, I'm only testing back-end for the moment so I've installed the following testing packages in functions/package.json :

  • mocha

  • chai

  • sinon

  • firebase-functions-test

  • @firebase/rules-unit-testing

  • Maybe it must be in the root's /package.json instead ?

End

Let me know if you need anything to help me.
Also, I'm pretty new to all of this (Firebase, testing, asking on stackoverflow), so please don't be rude if I've made mistakes.

Have a nice day!

0 Answers
Related