firestore-snapshot-utils
Version:
**Utils for testing Firestore DB snapshots**
49 lines (34 loc) • 1.81 kB
Markdown
**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.
- **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('<diff content>')
console.log(getDiffFromDBSnapshotChanges(changes))
```
See [docs](docs/README.md)