You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -157,6 +159,14 @@ React Firebase Admin is our in-house admin dashboard boilerplate, used in many o
157
159
-[Camelcase](https://github.com/sindresorhus/camelcase) (★ 423) convert a dash/dot/underscore/space separated string to camelCase.
158
160
-[Resize Image](https://github.com/firebase/extensions/tree/master/storage-resize-images) (★ 372) Firebase Extension to create resized versions of images uploaded to Cloud Storage.
159
161
162
+
#### Unit Testing
163
+
164
+
-[Firebase-functions-test](https://github.com/firebase/firebase-functions-test) (★ 117) unit testing library for Cloud Functions for Firebase.
165
+
-[Mocha](https://github.com/mochajs/mocha) (★ 19.4k) simple, flexible, fun javascript test framework for node.js & the browser.
166
+
-[Chai](https://github.com/chaijs/chai) (★ 6.8k) BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
167
+
-[Chai-as-promised](https://github.com/domenic/chai-as-promised/) (★ 1.4k) Extends Chai with assertions about promises.
168
+
-[Ts-node](https://github.com/TypeStrong/ts-node) (★ 7k) TypeScript execution and REPL for node.js, with source map support.
169
+
160
170
## Prerequisites
161
171
162
172
-[Firebase](https://firebase.google.com/) account in order to set up the serverless BaaS for the project.
@@ -332,15 +342,27 @@ functions/
332
342
| │ └── onDelete.function.ts
333
343
│ ├── db/
334
344
│ │ ├── users/
335
-
│ │ ├── onCreate.function.ts
336
-
│ │ ├── onModify.function.ts
337
-
│ │ └── ... other database functions ...
345
+
│ │ │ ├── onCreate.function.ts
346
+
│ │ │ ├── onModify.function.ts
347
+
│ │ │ └── ... other database functions ...
338
348
│ ├── storage/
339
349
│ │ ... storage functions ...
340
350
│ ├── https/
341
351
│ │ ├── createUser.function.ts
342
-
│ │ └── ... other https functions ...
352
+
│ │ └── ... other https functions ...
343
353
│ └── index.ts
354
+
├── test/
355
+
│ ├── db/
356
+
│ │ ├── users/
357
+
│ │ │ ├── onDelete.test.ts
358
+
│ │ │ ├── onUpdate.test.ts
359
+
│ │ │ └── ... other database tests ...
360
+
│ ├── https/
361
+
│ │ ├── createUser.test.ts
362
+
│ │ └── ... other https tests ...
363
+
│ └── util/
364
+
│ ├── config.ts
365
+
│
344
366
```
345
367
346
368
### Installing dependencies
@@ -416,6 +438,24 @@ After it initializes, you should get your endpoints to test your HTTP functions:
416
438
417
439
More information about the [Firebase Emulator](https://firebase.google.com/docs/rules/emulator-setup).
418
440
441
+
### Testing functions in online mode
442
+
443
+
Testing your cloud functions online is very simple and easy.
444
+
445
+
For that, you only have to set the variables localted in the env.example.json inside /functions folder. (Remember to rename the file to env.json)
446
+
447
+
Follow these steps for setting up your env.json file:
448
+
449
+
- The first 3 properties **_"databaseURL"_**, **_"storageBucket"_** and **_"projectId"_** are the same ones previously added to the frontend .env file.
450
+
- For **_"serviceAccountKey"_** you should do the following:
451
+
- Go to your proyect in the Firebase dashboard, click on **_Project settings_** and then click on **_Service accounts_** tab.
452
+
- After that you'll be able to click on **_Generate new private key_** button and a json file containing your service account's credentials will be downloaded.
453
+
- Place that file in your project and include the location of it into the **_"serviceAccountKey"_** in your env.json file.
454
+
455
+
After that, open your terminal, navigate to the /functions folder and execute **npm test**.
456
+
457
+
_Warning: Use extra caution when handling service account credentials in your code. Do not commit them to a public repository, deploy them in a client app, or expose them in any way that could compromise the security of your Firebase project._
458
+
419
459
### Deployment
420
460
421
461
When a pull request gets merged into development, functions are deployed automatically to the staging project in Firebase. Likewise, when merging/pushing into master, they're deployed to production.
@@ -742,6 +782,7 @@ We'd like to thank these awesome people who made this whole thing happen:
0 commit comments