@dereekb/firebase 13.10.8 → 13.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/index.esm.js CHANGED
@@ -258,6 +258,7 @@ function _ts_generator$6(thisArg, body) {
258
258
  * ```
259
259
  *
260
260
  * @param driver - The base driver to wrap with fuzzing behavior.
261
+ * @returns A {@link TestingFirestoreAccessorDriver} with `collection`, `subcollection`, and `collectionGroup` rewired to use fuzzed paths, plus helpers to inspect the fuzz map.
261
262
  */ function makeTestingFirestoreAccesorDriver(driver) {
262
263
  var fuzzerKey = 0;
263
264
  var time = new Date().getTime();
@@ -314,8 +315,8 @@ function _ts_generator$6(thisArg, body) {
314
315
  /**
315
316
  * Extends the input drivers to generate new drivers for a testing environment.
316
317
  *
317
- * @param drivers
318
- * @returns
318
+ * @param drivers - The base Firestore drivers to wrap.
319
+ * @returns A {@link TestingFirestoreDrivers} marked with `firestoreDriverType: 'testing'` and a wrapped accessor driver from {@link makeTestingFirestoreAccesorDriver}.
319
320
  */ function makeTestingFirestoreDrivers(drivers) {
320
321
  return _object_spread_props$2(_object_spread$3({}, drivers), {
321
322
  firestoreDriverType: 'testing',
@@ -411,6 +412,7 @@ var bucketTestNameKey = 0;
411
412
  *
412
413
  * @param driver - The base storage accessor driver to wrap.
413
414
  * @param config - Optional configuration controlling test bucket behavior.
415
+ * @returns A driver with the same surface as `driver`, but with `getDefaultBucket` overridden to return a unique test bucket name when {@link MakeTestingFirebaseStorageAccessorDriverConfig.useTestDefaultBucket} requires it.
414
416
  */ function makeTestingFirebaseStorageAccesorDriver(driver, config) {
415
417
  var useTestDefaultBucket = (config !== null && config !== void 0 ? config : {}).useTestDefaultBucket;
416
418
  // The default bucket is only used if another bucket is not input.
@@ -427,8 +429,9 @@ var bucketTestNameKey = 0;
427
429
  /**
428
430
  * Extends the input drivers to generate new drivers for a testing environment.
429
431
  *
430
- * @param drivers
431
- * @returns
432
+ * @param drivers - The base Firebase Storage drivers to wrap.
433
+ * @param config - Optional config forwarded to {@link makeTestingFirebaseStorageAccesorDriver}; controls test-bucket override behavior.
434
+ * @returns A {@link TestingFirebaseStorageDrivers} marked with `storageDriverType: 'testing'` and a wrapped accessor driver.
432
435
  */ function makeTestingFirebaseStorageDrivers(drivers, config) {
433
436
  return _object_spread_props$1(_object_spread$2({}, drivers), {
434
437
  storageDriverType: 'testing',
@@ -846,6 +849,11 @@ function _ts_generator$5(thisArg, body) {
846
849
  *
847
850
  * Combines the Firestore client drivers with the rules test environment and context
848
851
  * to produce a context suitable for client-side Firestore tests.
852
+ *
853
+ * @param drivers - Testing Firestore drivers used to back the context (typically with collection name fuzzing).
854
+ * @param rulesTestEnvironment - The shared `@firebase/rules-unit-testing` environment for the suite.
855
+ * @param rulesTestContext - The per-test rules context (authenticated or unauthenticated) used to obtain the Firestore instance.
856
+ * @returns A {@link RulesUnitTestTestFirestoreContext} that exposes the rules-test environment and context alongside the standard Firestore context.
849
857
  */ function makeRulesTestFirestoreContext(drivers, rulesTestEnvironment, rulesTestContext) {
850
858
  var context = _object_spread_props(_object_spread$1({}, firestoreContextFactory(drivers)(rulesTestContext.firestore())), {
851
859
  drivers: drivers,
@@ -859,6 +867,11 @@ function _ts_generator$5(thisArg, body) {
859
867
  *
860
868
  * Combines the Storage client drivers with the rules test environment and context
861
869
  * to produce a context suitable for client-side Firebase Storage tests.
870
+ *
871
+ * @param drivers - Testing Firebase Storage drivers used to back the context (typically with a unique test bucket).
872
+ * @param rulesTestEnvironment - The shared `@firebase/rules-unit-testing` environment for the suite.
873
+ * @param rulesTestContext - The per-test rules context used to obtain the Storage instance.
874
+ * @returns A {@link RulesUnitTestTestFirebaseStorageContext} that exposes the rules-test environment and context alongside the standard Storage context.
862
875
  */ function makeRulesTestFirebaseStorageContext(drivers, rulesTestEnvironment, rulesTestContext) {
863
876
  var context = _object_spread_props(_object_spread$1({}, firebaseStorageContextFactory(drivers)(rulesTestContext.storage())), {
864
877
  drivers: drivers,
@@ -942,6 +955,9 @@ function _ts_generator$5(thisArg, body) {
942
955
  * preventing interference between parallel workers sharing the same Firebase Storage emulator. The Storage
943
956
  * emulator maintains rules globally (not per-project), so concurrent `setRules` calls from multiple workers
944
957
  * can momentarily leave the emulator in a transitional state that causes `storage/unauthorized` errors.
958
+ *
959
+ * @param inputConfig - Optional partial config; `testEnvironment` defaults to an empty object and `rulesContext` defaults to undefined (unauthenticated).
960
+ * @returns A function that, given a `buildTests` callback, registers Vitest hooks (`beforeAll`/`afterAll`/`beforeEach`/`afterEach`) and invokes the callback with a {@link RulesUnitTestFirebaseTestingContextFixture}.
945
961
  */ var firebaseRulesUnitTestBuilder = function firebaseRulesUnitTestBuilder(inputConfig) {
946
962
  var _ref;
947
963
  var config = {
@@ -1253,8 +1269,8 @@ function _is_native_reflect_construct$4() {
1253
1269
  /**
1254
1270
  * Used to build a mockItemCollection from a firestore instance with a converter setup.
1255
1271
  *
1256
- * @param firestore
1257
- * @returns
1272
+ * @param context - The Firestore context to resolve the root collection against.
1273
+ * @returns A typed {@link CollectionReference} for the root MockItem collection.
1258
1274
  */ function mockItemCollectionReference(context) {
1259
1275
  return context.collection(mockItemIdentity.collectionName);
1260
1276
  }
@@ -1266,6 +1282,9 @@ function _is_native_reflect_construct$4() {
1266
1282
  * const collection = mockItemFirestoreCollection(firestoreContext);
1267
1283
  * const doc = collection.documentAccessor().newDocument();
1268
1284
  * ```
1285
+ *
1286
+ * @param firestoreContext - The Firestore context (test or production) used to resolve the underlying collection reference.
1287
+ * @returns A {@link MockItemFirestoreCollection} wired with the {@link mockItemConverter} and {@link mockItemIdentity}.
1269
1288
  */ function mockItemFirestoreCollection(firestoreContext) {
1270
1289
  return firestoreContext.firestoreCollection({
1271
1290
  converter: mockItemConverter,
@@ -1370,13 +1389,11 @@ function _is_native_reflect_construct$4() {
1370
1389
  })
1371
1390
  });
1372
1391
  /**
1373
- * Used to build a mockItemCollection from a firestore instance with a converter setup.
1374
- *
1375
- * @param firestore
1376
- * @returns
1377
- */ /**
1378
1392
  * Creates a factory that produces {@link CollectionReference} instances for {@link MockItemPrivate}
1379
1393
  * subcollections under a given {@link MockItemDocument} parent.
1394
+ *
1395
+ * @param context - The Firestore context used to resolve subcollections.
1396
+ * @returns A function that, given a parent {@link MockItemDocument}, returns a typed {@link CollectionReference} for that parent's MockItemPrivate subcollection.
1380
1397
  */ function mockItemPrivateCollectionReferenceFactory(context) {
1381
1398
  return function(parent) {
1382
1399
  return context.subcollection(parent.documentRef, mockItemPrivateIdentity.collectionName);
@@ -1384,6 +1401,9 @@ function _is_native_reflect_construct$4() {
1384
1401
  }
1385
1402
  /**
1386
1403
  * Creates a factory for producing {@link MockItemPrivateFirestoreCollection} instances bound to a parent {@link MockItemDocument}.
1404
+ *
1405
+ * @param firestoreContext - The Firestore context used to resolve the underlying subcollection.
1406
+ * @returns A factory that, given a parent {@link MockItemDocument}, returns a single-item collection wired with {@link mockItemPrivateConverter}.
1387
1407
  */ function mockItemPrivateFirestoreCollection(firestoreContext) {
1388
1408
  var factory = mockItemPrivateCollectionReferenceFactory(firestoreContext);
1389
1409
  return function(parent) {
@@ -1401,11 +1421,17 @@ function _is_native_reflect_construct$4() {
1401
1421
  }
1402
1422
  /**
1403
1423
  * Creates a {@link CollectionGroup} reference for querying all {@link MockItemPrivate} documents across parents.
1424
+ *
1425
+ * @param context - The Firestore context used to resolve the collection group.
1426
+ * @returns A typed {@link CollectionGroup} reference for the MockItemPrivate collection name.
1404
1427
  */ function mockItemPrivateCollectionReference(context) {
1405
1428
  return context.collectionGroup(mockItemPrivateIdentity.collectionName);
1406
1429
  }
1407
1430
  /**
1408
1431
  * Creates a {@link MockItemPrivateFirestoreCollectionGroup} for cross-parent queries on {@link MockItemPrivate}.
1432
+ *
1433
+ * @param firestoreContext - The Firestore context used to resolve the underlying collection group reference.
1434
+ * @returns A typed {@link MockItemPrivateFirestoreCollectionGroup} wired with the {@link mockItemPrivateConverter}.
1409
1435
  */ function mockItemPrivateFirestoreCollectionGroup(firestoreContext) {
1410
1436
  return firestoreContext.firestoreCollectionGroup({
1411
1437
  modelIdentity: mockItemPrivateIdentity,
@@ -1458,10 +1484,11 @@ var mockItemUserIdentifier = '0';
1458
1484
  })
1459
1485
  });
1460
1486
  /**
1461
- * Used to build a mockItemCollection from a firestore instance with a converter setup.
1487
+ * Creates a factory that produces {@link CollectionReference} instances for {@link MockItemUser}
1488
+ * subcollections under a given {@link MockItemDocument} parent.
1462
1489
  *
1463
- * @param firestore
1464
- * @returns
1490
+ * @param context - The Firestore context used to resolve subcollections.
1491
+ * @returns A function that, given a parent {@link MockItemDocument}, returns a typed {@link CollectionReference} for that parent's MockItemUser subcollection.
1465
1492
  */ function mockItemUserCollectionReferenceFactory(context) {
1466
1493
  return function(parent) {
1467
1494
  return context.subcollection(parent.documentRef, mockItemUserCollectionName);
@@ -1472,6 +1499,9 @@ var mockItemUserIdentifier = '0';
1472
1499
  */ var mockItemUserAccessorFactory = copyUserRelatedDataAccessorFactoryFunction();
1473
1500
  /**
1474
1501
  * Creates a factory for producing {@link MockItemUserFirestoreCollection} instances bound to a parent {@link MockItemDocument}.
1502
+ *
1503
+ * @param firestoreContext - The Firestore context used to resolve the underlying subcollection.
1504
+ * @returns A factory that, given a parent {@link MockItemDocument}, returns a per-parent collection wired with {@link mockItemUserConverter} and {@link mockItemUserAccessorFactory}.
1475
1505
  */ function mockItemUserFirestoreCollection(firestoreContext) {
1476
1506
  var factory = mockItemUserCollectionReferenceFactory(firestoreContext);
1477
1507
  return function(parent) {
@@ -1490,11 +1520,17 @@ var mockItemUserIdentifier = '0';
1490
1520
  }
1491
1521
  /**
1492
1522
  * Creates a {@link CollectionGroup} reference for querying all {@link MockItemUser} documents across parents.
1523
+ *
1524
+ * @param context - The Firestore context used to resolve the collection group.
1525
+ * @returns A typed {@link CollectionGroup} reference for the MockItemUser collection name.
1493
1526
  */ function mockItemUserCollectionReference(context) {
1494
1527
  return context.collectionGroup(mockItemUserCollectionName);
1495
1528
  }
1496
1529
  /**
1497
1530
  * Creates a {@link MockItemUserFirestoreCollectionGroup} for cross-parent queries on {@link MockItemUser}.
1531
+ *
1532
+ * @param firestoreContext - The Firestore context used to resolve the underlying collection group reference.
1533
+ * @returns A typed {@link MockItemUserFirestoreCollectionGroup} wired with the {@link mockItemUserConverter} and {@link mockItemUserAccessorFactory}.
1498
1534
  */ function mockItemUserFirestoreCollectionGroup(firestoreContext) {
1499
1535
  return firestoreContext.firestoreCollectionGroup({
1500
1536
  modelIdentity: mockItemUserIdentity,
@@ -1544,6 +1580,9 @@ var mockItemUserIdentifier = '0';
1544
1580
  /**
1545
1581
  * Creates a factory that produces {@link CollectionReference} instances for {@link MockItemSubItem}
1546
1582
  * subcollections under a given {@link MockItemDocument} parent.
1583
+ *
1584
+ * @param context - The Firestore context used to resolve subcollections.
1585
+ * @returns A function that, given a parent {@link MockItemDocument}, returns a typed {@link CollectionReference} for that parent's MockItemSubItem subcollection.
1547
1586
  */ function mockItemSubItemCollectionReferenceFactory(context) {
1548
1587
  return function(parent) {
1549
1588
  return context.subcollection(parent.documentRef, mockItemSubItemIdentity.collectionName);
@@ -1551,6 +1590,9 @@ var mockItemUserIdentifier = '0';
1551
1590
  }
1552
1591
  /**
1553
1592
  * Creates a factory for producing {@link MockItemSubItemFirestoreCollection} instances bound to a parent {@link MockItemDocument}.
1593
+ *
1594
+ * @param firestoreContext - The Firestore context used to resolve the underlying subcollection.
1595
+ * @returns A factory that, given a parent {@link MockItemDocument}, returns a per-parent collection wired with {@link mockItemSubItemConverter}.
1554
1596
  */ function mockItemSubItemFirestoreCollection(firestoreContext) {
1555
1597
  var factory = mockItemSubItemCollectionReferenceFactory(firestoreContext);
1556
1598
  return function(parent) {
@@ -1568,11 +1610,17 @@ var mockItemUserIdentifier = '0';
1568
1610
  }
1569
1611
  /**
1570
1612
  * Creates a {@link CollectionGroup} reference for querying all {@link MockItemSubItem} documents across parents.
1613
+ *
1614
+ * @param context - The Firestore context used to resolve the collection group.
1615
+ * @returns A typed {@link CollectionGroup} reference for the MockItemSubItem collection name.
1571
1616
  */ function mockItemSubItemCollectionReference(context) {
1572
1617
  return context.collectionGroup(mockItemSubItemIdentity.collectionName);
1573
1618
  }
1574
1619
  /**
1575
1620
  * Creates a {@link MockItemSubItemFirestoreCollectionGroup} for cross-parent queries on {@link MockItemSubItem}.
1621
+ *
1622
+ * @param firestoreContext - The Firestore context used to resolve the underlying collection group reference.
1623
+ * @returns A typed {@link MockItemSubItemFirestoreCollectionGroup} wired with the {@link mockItemSubItemConverter}.
1576
1624
  */ function mockItemSubItemFirestoreCollectionGroup(firestoreContext) {
1577
1625
  return firestoreContext.firestoreCollectionGroup({
1578
1626
  modelIdentity: mockItemSubItemIdentity,
@@ -1621,6 +1669,9 @@ var mockItemUserIdentifier = '0';
1621
1669
  /**
1622
1670
  * Creates a factory that produces {@link CollectionReference} instances for {@link MockItemSubItemDeep}
1623
1671
  * subcollections under a given {@link MockItemSubItemDocument} parent.
1672
+ *
1673
+ * @param context - The Firestore context used to resolve subcollections.
1674
+ * @returns A function that, given a parent {@link MockItemSubItemDocument}, returns a typed {@link CollectionReference} for that parent's MockItemSubItemDeep subcollection.
1624
1675
  */ function mockItemSubItemDeepCollectionReferenceFactory(context) {
1625
1676
  return function(parent) {
1626
1677
  return context.subcollection(parent.documentRef, mockItemSubItemDeepIdentity.collectionName);
@@ -1628,6 +1679,9 @@ var mockItemUserIdentifier = '0';
1628
1679
  }
1629
1680
  /**
1630
1681
  * Creates a factory for producing {@link MockItemSubItemDeepFirestoreCollection} instances bound to a parent {@link MockItemSubItemDocument}.
1682
+ *
1683
+ * @param firestoreContext - The Firestore context used to resolve the underlying subcollection.
1684
+ * @returns A factory that, given a parent {@link MockItemSubItemDocument}, returns a per-parent collection wired with {@link mockItemSubItemDeepConverter}.
1631
1685
  */ function mockItemSubItemDeepFirestoreCollection(firestoreContext) {
1632
1686
  var factory = mockItemSubItemDeepCollectionReferenceFactory(firestoreContext);
1633
1687
  return function(parent) {
@@ -1645,11 +1699,17 @@ var mockItemUserIdentifier = '0';
1645
1699
  }
1646
1700
  /**
1647
1701
  * Creates a {@link CollectionGroup} reference for querying all {@link MockItemSubItemDeep} documents across parents.
1702
+ *
1703
+ * @param context - The Firestore context used to resolve the collection group.
1704
+ * @returns A typed {@link CollectionGroup} reference for the MockItemSubItemDeep collection name.
1648
1705
  */ function mockItemSubItemDeepCollectionReference(context) {
1649
1706
  return context.collectionGroup(mockItemSubItemDeepIdentity.collectionName);
1650
1707
  }
1651
1708
  /**
1652
1709
  * Creates a {@link MockItemSubItemDeepFirestoreCollectionGroup} for cross-parent queries on {@link MockItemSubItemDeep}.
1710
+ *
1711
+ * @param firestoreContext - The Firestore context used to resolve the underlying collection group reference.
1712
+ * @returns A typed {@link MockItemSubItemDeepFirestoreCollectionGroup} wired with the {@link mockItemSubItemDeepConverter}.
1653
1713
  */ function mockItemSubItemDeepFirestoreCollectionGroup(firestoreContext) {
1654
1714
  return firestoreContext.firestoreCollectionGroup({
1655
1715
  modelIdentity: mockItemSubItemDeepIdentity,
@@ -1704,6 +1764,9 @@ function _class_call_check$4(instance, Constructor) {
1704
1764
  * Creates a concrete {@link MockItemCollections} instance with all collections bound to the given {@link FirestoreContext}.
1705
1765
  *
1706
1766
  * This is the primary way to instantiate the full set of mock collections for a test run.
1767
+ *
1768
+ * @param firestoreContext - The Firestore context (typically a {@link TestFirestoreContext}) that backs every collection.
1769
+ * @returns A fully populated {@link MockItemCollections} with each mock collection, factory, and collection group wired to `firestoreContext`.
1707
1770
  */ function makeMockItemCollections(firestoreContext) {
1708
1771
  return {
1709
1772
  mockItemCollection: mockItemFirestoreCollection(firestoreContext),
@@ -1929,6 +1992,9 @@ function _is_native_reflect_construct$3() {
1929
1992
  {
1930
1993
  key: "firestoreCollection",
1931
1994
  get: /**
1995
+ * Backwards-compatible alias for {@link MockItemCollectionFixtureInstance.mockItemCollection}.
1996
+ *
1997
+ * @returns The root {@link MockItemFirestoreCollection} from the fixture's underlying {@link MockItemCollections}.
1932
1998
  * @deprecated Use mockItemCollection instead.
1933
1999
  */ function get() {
1934
2000
  return this.collections.mockItemCollection;
@@ -2017,6 +2083,9 @@ function _is_native_reflect_construct$3() {
2017
2083
  * it('should work', () => { ... });
2018
2084
  * }));
2019
2085
  * ```
2086
+ *
2087
+ * @param _config - Reserved for future setup/teardown configuration; currently unused.
2088
+ * @returns A factory builder that wraps a parent {@link TestFirestoreContextFixture} with a {@link MockItemCollectionFixture} per test.
2020
2089
  */ function testWithMockItemCollectionFixture(_config) {
2021
2090
  return instanceWrapTestContextFactory({
2022
2091
  wrapFixture: function wrapFixture(fixture) {
@@ -2183,6 +2252,9 @@ function _is_native_reflect_construct$2() {
2183
2252
  * it('should upload', () => { ... });
2184
2253
  * }));
2185
2254
  * ```
2255
+ *
2256
+ * @param _config - Reserved for future setup/teardown configuration; currently unused.
2257
+ * @returns A factory builder that wraps a parent {@link TestFirebaseStorageContextFixture} with a {@link MockItemStorageFixture} per test.
2186
2258
  */ function testWithMockItemStorageFixture(_config) {
2187
2259
  return instanceWrapTestContextFactory({
2188
2260
  wrapFixture: function wrapFixture(fixture) {
@@ -2355,11 +2427,17 @@ function _is_native_reflect_construct$1() {
2355
2427
  * const constraint = mockItemWithValue('hello');
2356
2428
  * const results = await collection.query(constraint);
2357
2429
  * ```
2430
+ *
2431
+ * @param value - The exact `value` to match.
2432
+ * @returns A `where('value', '==', value)` constraint typed for {@link MockItem}.
2358
2433
  */ function mockItemWithValue(value) {
2359
2434
  return where('value', '==', value);
2360
2435
  }
2361
2436
  /**
2362
2437
  * Creates a Firestore query constraint that filters {@link MockItem} documents by their `test` boolean field.
2438
+ *
2439
+ * @param test - The boolean value of the `test` field to match.
2440
+ * @returns A `where('test', '==', test)` constraint.
2363
2441
  */ function mockItemWithTestValue(test) {
2364
2442
  return where('test', '==', test);
2365
2443
  }
@@ -2377,8 +2455,8 @@ function _is_native_reflect_construct$1() {
2377
2455
  * From:
2378
2456
  * https://medium.com/firebase-developers/how-to-query-collections-in-firestore-under-a-certain-path-6a0d686cebd2
2379
2457
  *
2380
- * @param parent
2381
- * @returns
2458
+ * @param mockItem - The parent {@link MockItem} document reference whose descendant documents the constraint should bound to.
2459
+ * @returns An array of constraints (suitable for use on a collection group query) that restricts results to documents under the given parent path.
2382
2460
  */ function allChildMockItemSubItemDeepsWithinMockItem(mockItem) {
2383
2461
  return allChildDocumentsUnderParent(mockItem);
2384
2462
  }
@@ -5056,6 +5134,27 @@ function _ts_generator$3(thisArg, body) {
5056
5134
  };
5057
5135
  }
5058
5136
  }
5137
+ /**
5138
+ * Creates a gate that calls `done()` once both `setSeen()` and `setCompleted()` have been invoked.
5139
+ *
5140
+ * Used to coordinate streamed-emission and post-mutation callbacks in stream-update tests.
5141
+ *
5142
+ * @param done - The Vitest async-test completion callback to invoke once both sides of the gate have fired.
5143
+ * @returns A two-method gate; the test calls `setSeen()` from the stream subscription and `setCompleted()` from the mutation continuation, and `done()` runs only after both have happened (in either order).
5144
+ */ function makeAwaitBothGate(done) {
5145
+ var seen = false;
5146
+ var completed = false;
5147
+ return {
5148
+ setSeen: function setSeen() {
5149
+ seen = true;
5150
+ if (completed) done();
5151
+ },
5152
+ setCompleted: function setCompleted() {
5153
+ completed = true;
5154
+ if (seen) done();
5155
+ }
5156
+ };
5157
+ }
5059
5158
  /**
5060
5159
  * Describes query driver tests, using a MockItemCollectionFixture.
5061
5160
  *
@@ -6194,20 +6293,13 @@ function _ts_generator$3(thisArg, body) {
6194
6293
  sub.destroy();
6195
6294
  });
6196
6295
  it('should emit when the query results update (an item is added).', callbackTest(function(done) {
6197
- var tryComplete = function tryComplete() {
6198
- if (addSeen && addCompleted) {
6199
- done();
6200
- }
6201
- };
6202
6296
  var itemsToAdd = 1;
6203
- var addCompleted = false;
6204
- var addSeen = false;
6297
+ var gate = makeAwaitBothGate(done);
6205
6298
  sub.subscription = querySubItems().streamDocs().pipe(filter(function(x) {
6206
6299
  return x.docs.length > allSubItems.length;
6207
6300
  })).subscribe(function(results) {
6208
- addSeen = true;
6209
6301
  expect(results.docs.length).toBe(allSubItems.length + itemsToAdd);
6210
- tryComplete();
6302
+ gate.setSeen();
6211
6303
  });
6212
6304
  // add one item
6213
6305
  void makeDocuments(f.instance.mockItemSubItemCollection(parentA).documentAccessor(), {
@@ -6218,32 +6310,23 @@ function _ts_generator$3(thisArg, body) {
6218
6310
  };
6219
6311
  }
6220
6312
  }).then(function() {
6221
- addCompleted = true;
6222
- tryComplete();
6313
+ gate.setCompleted();
6223
6314
  });
6224
6315
  }));
6225
6316
  it('should emit when the query results update (an item is removed).', callbackTest(function(done) {
6226
- var tryComplete = function tryComplete() {
6227
- if (deleteSeen && deleteCompleted) {
6228
- done();
6229
- }
6230
- };
6231
6317
  var itemsToRemove = 1;
6232
- var deleteCompleted = false;
6233
- var deleteSeen = false;
6318
+ var gate = makeAwaitBothGate(done);
6234
6319
  sub.subscription = querySubItems().streamDocs().pipe(filter(function(x) {
6235
6320
  return x.docs.length < allSubItems.length;
6236
6321
  })).subscribe(function(results) {
6237
- deleteSeen = true;
6238
6322
  expect(results.docs.length).toBe(allSubItems.length - itemsToRemove);
6239
- tryComplete();
6323
+ gate.setSeen();
6240
6324
  });
6241
6325
  void allSubItems[0].accessor.exists().then(function(exists) {
6242
6326
  expect(exists).toBe(true);
6243
6327
  // remove one item
6244
6328
  return allSubItems[0].accessor.delete().then(function() {
6245
- deleteCompleted = true;
6246
- tryComplete();
6329
+ gate.setCompleted();
6247
6330
  });
6248
6331
  });
6249
6332
  }));
@@ -6442,20 +6525,13 @@ function _ts_generator$3(thisArg, body) {
6442
6525
  sub.destroy();
6443
6526
  });
6444
6527
  it('should emit when the query results update (an item is added).', callbackTest(function(done) {
6445
- var tryComplete = function tryComplete() {
6446
- if (addSeen && addCompleted) {
6447
- done();
6448
- }
6449
- };
6450
6528
  var itemsToAdd = 1;
6451
- var addCompleted = false;
6452
- var addSeen = false;
6529
+ var gate = makeAwaitBothGate(done);
6453
6530
  sub.subscription = queryDocument().streamDocs().pipe(filter(function(documents) {
6454
6531
  return documents.length > items.length;
6455
6532
  })).subscribe(function(documents) {
6456
- addSeen = true;
6457
6533
  expect(documents.length).toBe(items.length + itemsToAdd);
6458
- tryComplete();
6534
+ gate.setSeen();
6459
6535
  });
6460
6536
  // add one item
6461
6537
  void waitForMs(10).then(function() {
@@ -6468,32 +6544,23 @@ function _ts_generator$3(thisArg, body) {
6468
6544
  };
6469
6545
  }
6470
6546
  }).then(function() {
6471
- addCompleted = true;
6472
- tryComplete();
6547
+ gate.setCompleted();
6473
6548
  });
6474
6549
  });
6475
6550
  }));
6476
6551
  it('should emit when the query results update (an item is removed).', callbackTest(function(done) {
6477
- var tryComplete = function tryComplete() {
6478
- if (deleteSeen && deleteCompleted) {
6479
- done();
6480
- }
6481
- };
6482
6552
  var itemsToRemove = 1;
6483
- var deleteCompleted = false;
6484
- var deleteSeen = false;
6553
+ var gate = makeAwaitBothGate(done);
6485
6554
  sub.subscription = queryDocument().streamDocs().pipe(skip(1)).subscribe(function(documents) {
6486
- deleteSeen = true;
6487
6555
  expect(documents.length).toBe(items.length - itemsToRemove);
6488
- tryComplete();
6556
+ gate.setSeen();
6489
6557
  });
6490
6558
  void waitForMs(10).then(function() {
6491
6559
  return items[0].exists().then(function(exists) {
6492
6560
  expect(exists).toBe(true);
6493
6561
  // remove one item
6494
6562
  return items[0].accessor.delete().then(function() {
6495
- deleteCompleted = true;
6496
- tryComplete();
6563
+ gate.setCompleted();
6497
6564
  });
6498
6565
  });
6499
6566
  });
@@ -6508,18 +6575,11 @@ function _ts_generator$3(thisArg, body) {
6508
6575
  sub.destroy();
6509
6576
  });
6510
6577
  it('should emit when the query results update (an item is added).', callbackTest(function(done) {
6511
- var tryComplete = function tryComplete() {
6512
- if (addSeen && addCompleted) {
6513
- done();
6514
- }
6515
- };
6516
6578
  var itemsToAdd = 1;
6517
- var addCompleted = false;
6518
- var addSeen = false;
6579
+ var gate = makeAwaitBothGate(done);
6519
6580
  sub.subscription = queryDocument().streamDocSnapshotDataPairs().pipe(filter(function(documents) {
6520
6581
  return documents.length > items.length;
6521
6582
  })).subscribe(function(documents) {
6522
- addSeen = true;
6523
6583
  expect(documents.length).toBe(items.length + itemsToAdd);
6524
6584
  documents.forEach(function(x) {
6525
6585
  // validate each document returned
@@ -6531,7 +6591,7 @@ function _ts_generator$3(thisArg, body) {
6531
6591
  expect(x.snapshot.ref).toBeDefined();
6532
6592
  expect(x.snapshot.id).toBe(x.document.id);
6533
6593
  });
6534
- tryComplete();
6594
+ gate.setSeen();
6535
6595
  });
6536
6596
  // add one item
6537
6597
  void waitForMs(10).then(function() {
@@ -6544,32 +6604,23 @@ function _ts_generator$3(thisArg, body) {
6544
6604
  };
6545
6605
  }
6546
6606
  }).then(function() {
6547
- addCompleted = true;
6548
- tryComplete();
6607
+ gate.setCompleted();
6549
6608
  });
6550
6609
  });
6551
6610
  }));
6552
6611
  it('should emit when the query results update (an item is removed).', callbackTest(function(done) {
6553
- var tryComplete = function tryComplete() {
6554
- if (deleteSeen && deleteCompleted) {
6555
- done();
6556
- }
6557
- };
6558
6612
  var itemsToRemove = 1;
6559
- var deleteCompleted = false;
6560
- var deleteSeen = false;
6613
+ var gate = makeAwaitBothGate(done);
6561
6614
  sub.subscription = queryDocument().streamDocs().pipe(skip(1)).subscribe(function(documents) {
6562
- deleteSeen = true;
6563
6615
  expect(documents.length).toBe(items.length - itemsToRemove);
6564
- tryComplete();
6616
+ gate.setSeen();
6565
6617
  });
6566
6618
  void waitForMs(10).then(function() {
6567
6619
  return items[0].exists().then(function(exists) {
6568
6620
  expect(exists).toBe(true);
6569
6621
  // remove one item
6570
6622
  return items[0].accessor.delete().then(function() {
6571
- deleteCompleted = true;
6572
- tryComplete();
6623
+ gate.setCompleted();
6573
6624
  });
6574
6625
  });
6575
6626
  });
@@ -6597,20 +6648,13 @@ function _ts_generator$3(thisArg, body) {
6597
6648
  sub.destroy();
6598
6649
  });
6599
6650
  it('should emit when the query results update (an item is added).', callbackTest(function(done) {
6600
- var tryComplete = function tryComplete() {
6601
- if (addSeen && addCompleted) {
6602
- done();
6603
- }
6604
- };
6605
6651
  var itemsToAdd = 1;
6606
- var addCompleted = false;
6607
- var addSeen = false;
6652
+ var gate = makeAwaitBothGate(done);
6608
6653
  sub.subscription = query().streamDocs().pipe(filter(function(x) {
6609
6654
  return x.docs.length > items.length;
6610
6655
  })).subscribe(function(results) {
6611
- addSeen = true;
6612
6656
  expect(results.docs.length).toBe(items.length + itemsToAdd);
6613
- tryComplete();
6657
+ gate.setSeen();
6614
6658
  });
6615
6659
  // add one item
6616
6660
  void waitForMs(10).then(function() {
@@ -6623,32 +6667,23 @@ function _ts_generator$3(thisArg, body) {
6623
6667
  };
6624
6668
  }
6625
6669
  }).then(function() {
6626
- addCompleted = true;
6627
- tryComplete();
6670
+ gate.setCompleted();
6628
6671
  });
6629
6672
  });
6630
6673
  }));
6631
6674
  it('should emit when the query results update (an item is removed).', callbackTest(function(done) {
6632
- var tryComplete = function tryComplete() {
6633
- if (deleteSeen && deleteCompleted) {
6634
- done();
6635
- }
6636
- };
6637
6675
  var itemsToRemove = 1;
6638
- var deleteCompleted = false;
6639
- var deleteSeen = false;
6676
+ var gate = makeAwaitBothGate(done);
6640
6677
  sub.subscription = query().streamDocs().pipe(skip(1)).subscribe(function(results) {
6641
- deleteSeen = true;
6642
6678
  expect(results.docs.length).toBe(items.length - itemsToRemove);
6643
- tryComplete();
6679
+ gate.setSeen();
6644
6680
  });
6645
6681
  void waitForMs(10).then(function() {
6646
6682
  return items[0].accessor.exists().then(function(exists) {
6647
6683
  expect(exists).toBe(true);
6648
6684
  // remove one item
6649
6685
  return items[0].accessor.delete().then(function() {
6650
- deleteCompleted = true;
6651
- tryComplete();
6686
+ gate.setCompleted();
6652
6687
  });
6653
6688
  });
6654
6689
  });
package/test/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@dereekb/firebase/test",
3
- "version": "13.10.8",
3
+ "version": "13.11.0",
4
4
  "peerDependencies": {
5
- "@dereekb/date": "13.10.8",
6
- "@dereekb/firebase": "13.10.8",
7
- "@dereekb/model": "13.10.8",
8
- "@dereekb/rxjs": "13.10.8",
9
- "@dereekb/util": "13.10.8",
5
+ "@dereekb/date": "13.11.0",
6
+ "@dereekb/firebase": "13.11.0",
7
+ "@dereekb/model": "13.11.0",
8
+ "@dereekb/rxjs": "13.11.0",
9
+ "@dereekb/util": "13.11.0",
10
10
  "@firebase/rules-unit-testing": "5.0.0",
11
11
  "date-fns": "^4.1.0",
12
12
  "firebase": "^12.12.1",
@@ -58,6 +58,11 @@ export interface RulesUnitTestTestFirestoreContext extends TestFirestoreContext
58
58
  *
59
59
  * Combines the Firestore client drivers with the rules test environment and context
60
60
  * to produce a context suitable for client-side Firestore tests.
61
+ *
62
+ * @param drivers - Testing Firestore drivers used to back the context (typically with collection name fuzzing).
63
+ * @param rulesTestEnvironment - The shared `@firebase/rules-unit-testing` environment for the suite.
64
+ * @param rulesTestContext - The per-test rules context (authenticated or unauthenticated) used to obtain the Firestore instance.
65
+ * @returns A {@link RulesUnitTestTestFirestoreContext} that exposes the rules-test environment and context alongside the standard Firestore context.
61
66
  */
62
67
  export declare function makeRulesTestFirestoreContext(drivers: TestingFirestoreDrivers, rulesTestEnvironment: RulesTestEnvironment, rulesTestContext: RulesTestContext): TestFirestoreContext;
63
68
  /**
@@ -72,6 +77,11 @@ export interface RulesUnitTestTestFirebaseStorageContext extends TestFirebaseSto
72
77
  *
73
78
  * Combines the Storage client drivers with the rules test environment and context
74
79
  * to produce a context suitable for client-side Firebase Storage tests.
80
+ *
81
+ * @param drivers - Testing Firebase Storage drivers used to back the context (typically with a unique test bucket).
82
+ * @param rulesTestEnvironment - The shared `@firebase/rules-unit-testing` environment for the suite.
83
+ * @param rulesTestContext - The per-test rules context used to obtain the Storage instance.
84
+ * @returns A {@link RulesUnitTestTestFirebaseStorageContext} that exposes the rules-test environment and context alongside the standard Storage context.
75
85
  */
76
86
  export declare function makeRulesTestFirebaseStorageContext(drivers: TestingFirebaseStorageDrivers, rulesTestEnvironment: RulesTestEnvironment, rulesTestContext: RulesTestContext): TestFirebaseStorageContext;
77
87
  /**
@@ -112,6 +122,9 @@ export declare class RulesUnitTestFirebaseTestingContextFixture extends TestFire
112
122
  * preventing interference between parallel workers sharing the same Firebase Storage emulator. The Storage
113
123
  * emulator maintains rules globally (not per-project), so concurrent `setRules` calls from multiple workers
114
124
  * can momentarily leave the emulator in a transitional state that causes `storage/unauthorized` errors.
125
+ *
126
+ * @param inputConfig - Optional partial config; `testEnvironment` defaults to an empty object and `rulesContext` defaults to undefined (unauthenticated).
127
+ * @returns A function that, given a `buildTests` callback, registers Vitest hooks (`beforeAll`/`afterAll`/`beforeEach`/`afterEach`) and invokes the callback with a {@link RulesUnitTestFirebaseTestingContextFixture}.
115
128
  */
116
129
  export declare const firebaseRulesUnitTestBuilder: TestContextBuilderFunction<RulesUnitTestTestFirebaseInstance, RulesUnitTestFirebaseTestingContextFixture, RulesUnitTestingConfig>;
117
130
  /**