firebase / firebase-functions-test

MIT License
232 stars 48 forks source link

added method to clear all firestore data #71

Closed ShoeBoom closed 4 years ago

ShoeBoom commented 4 years ago

Description

Added a function to clear all firestore data between tests. Similar to https://github.com/firebase/firebase-js-sdk/blob/master/packages/testing/src/api/index.ts#L233

This makes it easier to run tests in offline mode

Code sample

const test = require("firebase-functions-test")({
    projectId: "project-id",
});

describe('test', () => {
    afterEach(async () => {
        await test.firestore.clearFirestoreData({ projectId: "project-id" });
    });
    it('test1', () => {
        // test that involes database changes
    });

    it('test2', () => {
        // test that involes database changes
    });
});

in order to implement tests I think I would need change: "test": "mocha .tmp/spec/index.spec.js" to "test": "firebase emulators:exec 'mocha .tmp/spec/index.spec.js'"

I want to know if there is a better way to implement tests before I started.