https://github.com/zirho/firebase-unit-test
Unit tests for Firebase
https://github.com/zirho/firebase-unit-test
database firebase firebase-console unit-testing
Last synced: 3 days ago
JSON representation
Unit tests for Firebase
- Host: GitHub
- URL: https://github.com/zirho/firebase-unit-test
- Owner: zirho
- Created: 2017-01-10T21:08:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-11T19:02:12.000Z (over 8 years ago)
- Last Synced: 2025-04-30T03:47:01.175Z (3 days ago)
- Topics: database, firebase, firebase-console, unit-testing
- Language: JavaScript
- Homepage: http://zirho.github.io/2017/01/11/firebase-unit-test/
- Size: 135 KB
- Stars: 10
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Firebase Unit Test
Demonstrate how to perform automated unit tests against database and rules
# Prerequisite
#### install node
#### install yarn package manager
https://yarnpkg.com/en/docs/install
#### install firebase-tools globally
```
yarn global add firebase-tools
```# Installation
## Clone and init the repo
```
git clone https://github.com/zirho/firebase-test
cd firebase-test
yarn install
```## Create and init firebase app
**Skip this if you already have a project setup and initiated**
#### Create a project
Go to https://console.firebase.google.com/project/
Create a new project
#### Get project configs
Update firebase.config.js with what your project gave you
```
vi src/firebase.config.js
```It should look something like this
```
export default {
apiKey: 'your-app-key',
authDomain: 'your-app-domain.firebaseapp.io',
databaseURL: 'https://your-firebase-database-url.firebaseio.com',
}
```#### Init the project
* refrence https://github.com/firebase/firebase-tools
```
firebase login
firebase init
```Follow the instructions
* select database
* select project name that you created
* select default for other options#### Get an admin credential file
* Go to "Project Setting" on firebase console.
* Select "SERVICE ACCOUNTS" tab
* Click on "GENERATE NEW PRIVATE KEY" at the bottom
* It will download a creds json file
* Copy that file to root folder of your project and rename it as 'firebase-admin.json'For Mac user
```
cp ~/Downloads/[downloaded file name].json ./firebase-admin.json
```#### Apply new rules for firebase database
Update `./database.rules.json` as you needed
And deploy it
```
firebase deploy --only database
```## Run tests
#### Run test once
```
yarn test-once
```#### Run tests any time *.js file updates (watch and run tests)
```
yarn test
```#### Run tests as an authenticated user
Pick a UID from firebase console > Authentication > USERS
Put the UID to the test
```
vi src/auth.test.js
```
```
describe('Authenticated firebase', () => {
let authedFirebase
const UID = 'vl7GjxgIRre1sD0ftesttesttesttest'
...
...
```#### Default tests will be successful, if your database has `/user/joshua` available


**Welcome to contribute**