cypress-firebase
Utilities to help testing firebase projects with cypress
Installation
$ npm i --save-dev cypress-firebase
Usage
Pre-Setup
Note: Skip to #3 if you already have Cypress tests in your project
- Install Cypress and add it to your package file:
npm i --save-dev cypress
- Add cypress folder by calling
cypress open
Setup
- Install deps
npm i cypress-firebase firebase-tools-extra cross-env --save-dev
- Add the following to the
scripts
section of your package.json
:
"build:testConfig": "cypress-firebase createTestEnvFile",
"test": "npm run build:testConfig && cross-env CYPRESS_baseUrl=http://localhost:3000 cypress run",
"test:ui": "npm run build:testConfig && cross-env CYPRESS_baseUrl=http://localhost:3000 cypress open",
- Add the following to the custom commands file (
cypress/support/commands.js
):
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';
import 'firebase/firestore';
import { attachCustomCommands } from 'cypress-firebase';
const fbConfig = {
};
window.fbInstance = firebase.initializeApp(fbConfig);
attachCustomCommands({ Cypress, cy, firebase })
Create Config
- Log into your app for the first time
- Go to the Auth tab of Firebase and get your UID
- Generate a service account -> save it as
serviceAccount.json
- Add your config info to
cypress/config.json
{
"TEST_UID": "<- uid of the user you want to test as ->",
"FIREBASE_PROJECT_ID": "<- projectId of your project ->"
}
Usage
docs here
Development
Install dependencies:
$ npm install
Run the example app at http://localhost:8080:
$ npm start
Run tests and watch for code changes using jest:
$ npm test
Lint src
and test
files:
$ npm run lint
Generate UMD output in the lib
folder (runs implicitly on npm version
):
$ npm run build
License
MIT