https://github.com/ericvera/firestore-snapshot-utils
Utils for testing Firestore DB snapshots
https://github.com/ericvera/firestore-snapshot-utils
Last synced: over 1 year ago
JSON representation
Utils for testing Firestore DB snapshots
- Host: GitHub
- URL: https://github.com/ericvera/firestore-snapshot-utils
- Owner: ericvera
- License: mit
- Created: 2024-10-08T01:24:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-26T03:31:29.000Z (over 1 year ago)
- Last Synced: 2025-03-17T04:43:29.395Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 2.34 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Firestore Snapshot Utils
**Utils for testing Firestore DB snapshots**
[](https://github.com/ericvera/firestore-snapshot-utils/blob/master/LICENSE)
[](https://npmjs.org/package/firestore-snapshot-utils)
A lightweight utility library for testing Firestore database snapshots, making it easier to track and verify changes in your Firestore collections.
## Features
- **Snapshot Retrieval**: Get snapshots from single or multiple Firestore queries
- **Change Detection**: Track document additions, removals, and modifications
- **Timestamp Normalization**: Consistent representation of Firestore timestamps for reliable comparisons
- **Property Masking**: Mask sensitive or variable properties (e.g., IDs, timestamps) for deterministic testing
- **Diff Generation**: Generate human-readable diffs of database changes
- **TypeScript Support**: Full TypeScript support with strict type checking
## Usage
```typescript
import {
getDBSnapshot,
getDBSnapshotChanges,
getDiffFromDBSnapshotChanges,
} from 'firestore-snapshot-utils'
// Get snapshots before changes
const beforeDocs = await getDBSnapshot(beforeQuery)
// Perform tests...
// Get snapshots after changes
const afterDocs = await getDBSnapshot(afterQuery)
// Compare snapshots and get changes
const changes = getDBSnapshotChanges(beforeDocs, afterDocs, {
// Optional: mask sensitive fields by collection
users: ['id', 'createdAt'],
})
// Generate human-readable diff. This can be used with expect.toMatchInlineSnapshot('')
console.log(getDiffFromDBSnapshotChanges(changes))
```
# API Reference
See [docs](docs/README.md)