1.1.1 • Published 5 months ago

firestore-snapshot-utils v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Firestore Snapshot Utils

Utils for testing Firestore DB snapshots

github license npm version

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

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))

API Reference

See docs

1.1.1

5 months ago

1.0.2

5 months ago

1.1.0

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

0.1.3

6 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.0

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago