0.1.0 • Published 2 years ago

firestore-testing-helpers v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Firestore Testing Helpers


This project is under development.

Please feel free to PullRequest and Issue.


This repository provides several helpers to facilitate testing in environments that use Firestore.

Installation

$ npm i -D firestore-testing-helpers

Emulator Connector Store

It provides an independent Firebase Connection for each test. Thus, you will be relieved from a very annoying test with runInBand.

import { FirebaseEmulatorConnectorStore } from "firestore-testing-helpers";
import { target } from '../path/to/test/target';


describe('User', () => {
  let connection;
  beforeAll(() => {
    connection = FirebaseEmulatorConnectorStore.getConnector().getAdminApp().firestore();
  });
...
});

Seeder

Helper to import fixture to firestore easily. It provides the ability to import specific data to a specific path as shown below.

import {Seeder} from 'firestore-testing-helpers';

export class UserSeeder extends Seeder {
  protected call() {
     return this.import('users', {
       john: {
         name: 'John',
         age: 28,
         __collections__: {}
       }
     });
  }
}

Seeder is very simple, just run the run method at test time.

import { FirebaseEmulatorConnectorStore } from "firestore-testing-helpers";
import { UserSeeder } from './fixtures/UserSeeder';

describe('User', () => {
  beforeAll(() => {
    return (new UserSeeder(FirestoreEmulatorConnectorStore.getConnector().getAdminFirestore())).run();
  });
...
});

Export

If you want to export the existing remote firestore data, please execute the following command.

$ firestore-export -a /path/to/serviceAccount.json -p collection/document
0.1.0

2 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago