# firebase-jest-testing

> Tools for testing Firebase back-end features, using Jest.

Latest version **0.0.3-beta.1** (published 2021-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install firebase-jest-testing
pnpm add firebase-jest-testing
yarn add firebase-jest-testing
bun add firebase-jest-testing
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3-beta.1 |
| Published | 2021-05-19 |
| First published | 2020-08-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | ^14.3 \|\| ^15 \|\| ^16 |
| Dependencies | 1 |
| Unpacked size | 73.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | akauppi |
| Keywords | firebase, firestore, jest |

## Links

- npm: https://www.npmjs.com/package/firebase-jest-testing
- Repository: https://github.com/akauppi/firebase-jest-testing
- Homepage: https://github.com/akauppi/firebase-jest-testing#readme
- Issues: https://github.com/akauppi/firebase-jest-testing/issues
- npm.io page: https://npm.io/package/firebase-jest-testing

## Dependencies (1)

- [node-fetch](https://npm.io/package/node-fetch.md) ^3.0.0-beta.9

## Recent versions

- 0.0.3-beta.1 (latest) — 2021-05-19
- 0.0.5-beta.4 (beta) — 2022-09-26
- 0.0.3-alpha.3 (alpha) — 2021-05-19
- 0.0.5-beta.3 — 2022-07-13
- 0.0.5-beta.2 — 2022-07-12
- 0.0.5-beta.1 — 2022-04-26
- 0.0.5-alpha.1 — 2022-04-09
- 0.0.4-alpha.5 — 2021-10-24
- 0.0.4-alpha.4 — 2021-08-25
- 0.0.4-alpha.3 — 2021-08-19
- 0.0.4-alpha.2 — 2021-07-19
- 0.0.3-beta.4b — 2021-06-30
- 0.0.3-beta.3 — 2021-06-13
- 0.0.3-beta.2 — 2021-05-27
- 0.0.3-beta.0 — 2021-05-19
- … 16 more at https://npm.io/package/firebase-jest-testing/versions

## README

# firebase-jest-testing

<!--
This README is visible on the npm package page: https://www.npmjs.com/package/firebase-jest-testing
-->

Tools for testing Firebase backend features, using Jest.

<img alt="a can" src="https://github.com/akauppi/firebase-jest-testing/raw/master/package/images/tin-can-alpha.jpg" width="350" />

<!--
<small><i>Image by A.Kauppi, CC by Attribution</small>
-->

Offers:

- 🥫Emulator detection. The library *automatically picks up the configuration* when running the tests. Less boilerplate!

- 🪶Light. Uses Firestore *REST API* so *no Firebase client JS SDK* is required. Add only `firebase-admin` and it's ready to be served!

- ⚡️Fast. Optimized for multithreading and Node.js. You'll likely max out your cores.

<!-- 
- Compatible. You may use *either* 8.x or 9.x (beta) client JS SDK in your application project. More freedom.
-->

- ‖‖‖ Security Rules are tested **immutably** - a passing write or delete operation does not change the data, and cannot disturb other tests. This is why we can parallelize the tests so much. No flaky tests.

- ⏲For testing Cloud Functions at the integration level, `.eventually` extension is added to the Jest arsenal.

- ﹛﹜Help functions for priming Firestore with *JSON data*.

- `+` Means for testing callables.

Only to be used with Jest 27.


## Requires

- Jest 27 - [milestone](https://github.com/facebook/jest/milestone/12)

   The module is built with ES modules in mind. Transitioning your project to Jest 27 is likely more meaningful than forking and backporting this code to Jest 26 and CommonJS.

## Using in your project

In your application project:

```
$ npm install --save-dev firebase-jest-testing@beta
```

Add this to the `jest.config.js`:

```
// Without this, the modules are not correctly loaded, due to being declared using 'exports'.
//
resolver: "firebase-jest-testing/src/cjs/jestResolver.cjs"
```

>Note: This is needed because (as of 27.0.0-next.9), Jest resolver does not treat modules with `exports` appropriately. This is likely going to be fixed before Jest 27 is out.


### Sample project

See the [GitHub repo](https://github.com/akauppi/firebase-jest-testing) `package.json` and `sample` folder for practical examples.

### Reference documentation
 
The contents are described in [Writing tests](https://github.com/akauppi/firebase-jest-testing/blob/master/package/Writing%20tests.md) (GitHub `HEAD`):

- [Testing Security Rules](https://github.com/akauppi/firebase-jest-testing/blob/master/package/Writing%20tests.md#testing-security-rules)
- Testing Cloud Functions [events](https://github.com/akauppi/firebase-jest-testing/blob/master/package/Writing%20tests.md#testing-cloud-functions-events) and [callables](https://github.com/akauppi/firebase-jest-testing/blob/master/package/Writing%20tests.md#testing-cloud-functions-callables)
- [Priming with JSON data](https://github.com/akauppi/firebase-jest-testing/blob/master/package/Writing%20tests.md#priming-with-json-data)
- [Why immutability matters](https://github.com/akauppi/firebase-jest-testing/blob/master/package/Writing%20tests.md#why-immutability-matters-and-a-bit-about-implementation) ..and a bit about [implementation](https://github.com/akauppi/firebase-jest-testing/blob/master/package/Writing%20tests.md#implementation-details)

<!-- Editor's note:
Did not find a way to link from 'npmjs.org' `README` to the `Writing tests.md` within the same published package.

The only solutions are:
- linking to another page (maybe keep by versions)
- bring all that text here?
-->

## Support

If you wish to support the development of this software, be in touch with the author. We'll figure out something nice! ;)

---
_Source: https://npm.io/package/firebase-jest-testing · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
