@@ -22,6 +22,48 @@ import { createMagnetarInstance } from '../helpers/createMagnetarInstance.js'
2222 assert . deepEqual ( pokedexModule . data . size , 151 )
2323 } )
2424}
25+ {
26+ const testName = 'stream with onFirstData (empty collection), close and stream again'
27+ test ( testName , async ( ) => {
28+ const { magnetar } = await createMagnetarInstance ( 'read' )
29+
30+ const emptyReadable = magnetar . collection ( 'emptyReopen' , {
31+ configPerStore : {
32+ remote : { firestorePath : 'magnetarTests/read/emptyReopen' } ,
33+ } ,
34+ } )
35+
36+ const onFirstDataPayloads : { empty ?: boolean } [ ] = [ ]
37+
38+ // First stream
39+ emptyReadable
40+ . stream ( { onFirstData : ( payload ) => onFirstDataPayloads . push ( payload ) } )
41+ . catch ( ( e : any ) => assert . fail ( e . message ) )
42+
43+ // Wait for initial snapshot
44+ await waitMs ( 500 )
45+
46+ // Close all streams and wait a tick
47+ emptyReadable . closeAllStreams ( )
48+ await waitMs ( 10 )
49+
50+ // Second stream
51+ emptyReadable
52+ . stream ( { onFirstData : ( payload ) => onFirstDataPayloads . push ( payload ) } )
53+ . catch ( ( e : any ) => assert . fail ( e . message ) )
54+
55+ // Wait for second snapshot
56+ await waitMs ( 500 )
57+
58+ // Expect onFirstData twice, both indicating empty collection
59+ assert . deepEqual ( onFirstDataPayloads . length , 2 )
60+ assert . deepEqual ( onFirstDataPayloads [ 0 ] , { empty : true } )
61+ assert . deepEqual ( onFirstDataPayloads [ 1 ] , { empty : true } )
62+
63+ // Cleanup
64+ emptyReadable . closeAllStreams ( )
65+ } )
66+ }
2567{
2668 const testName = 'stream (empty collection with read access)'
2769 test ( testName , async ( ) => {
0 commit comments