Skip to content

added method to clear all firestore data #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 3, 2020
Merged

added method to clear all firestore data #71

merged 7 commits into from
Sep 3, 2020

Conversation

ShoeBoom
Copy link
Contributor

@ShoeBoom ShoeBoom commented Sep 1, 2020

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.

make clearFirestoreData throw error when projectId is not specfied.
@laurenzlong laurenzlong requested a review from joehan September 1, 2020 18:08
Copy link
Contributor

@joehan joehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me! 1 nit around the type you used for params. For testing, I think the best option is to make a new npm command, and use that to write + run tests:
"integrationTest": "firebase emulators:exec 'mocha .tmp/spec/index.spec.js'"

@ShoeBoom ShoeBoom requested a review from joehan September 2, 2020 06:24
Copy link
Contributor

@joehan joehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one style nit. Thanks for the contribution! I'm planning to release a new version tomorrow to get this out.

@ShoeBoom ShoeBoom requested a review from joehan September 3, 2020 05:03
@joehan joehan merged commit 799d1c5 into firebase:master Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants