@@ -1363,8 +1363,8 @@ test('Stopping repository should stop storage provider updates', async (t) => {
1363
1363
} ) ;
1364
1364
1365
1365
test ( 'Streaming' , async ( t ) => {
1366
- t . plan ( 6 ) ;
1367
- const url = 'irrelevant ' ;
1366
+ t . plan ( 7 ) ;
1367
+ const url = 'http://unleash-test-streaming.app ' ;
1368
1368
const feature = {
1369
1369
name : 'feature' ,
1370
1370
enabled : true ,
@@ -1374,6 +1374,7 @@ test('Streaming', async (t) => {
1374
1374
} ,
1375
1375
] ,
1376
1376
} ;
1377
+ setup ( url , [ { ...feature , name : 'initialFetch' } ] ) ;
1377
1378
const storageProvider : StorageProvider < ClientFeaturesResponse > = new InMemStorageProvider ( ) ;
1378
1379
const eventSource = {
1379
1380
eventEmitter : new EventEmitter ( ) ,
@@ -1402,16 +1403,24 @@ test('Streaming', async (t) => {
1402
1403
eventSource,
1403
1404
} ) ;
1404
1405
1406
+ await repo . start ( ) ;
1407
+
1408
+ // first connection is ignored, since we do regular fetch
1409
+ eventSource . emit ( 'unleash-connected' , {
1410
+ type : 'unleash-connected' ,
1411
+ data : JSON . stringify ( { meta : { } , features : [ { ...feature , name : 'intialConnectedIgnored' } ] } ) ,
1412
+ } ) ;
1413
+
1405
1414
const before = repo . getToggles ( ) ;
1406
- t . deepEqual ( before , [ ] ) ;
1415
+ t . deepEqual ( before , [ { ... feature , name : 'initialFetch' } ] ) ;
1407
1416
1408
1417
// update with feature
1409
1418
eventSource . emit ( 'unleash-updated' , {
1410
1419
type : 'unleash-updated' ,
1411
- data : JSON . stringify ( { meta : { } , features : [ feature ] } ) ,
1420
+ data : JSON . stringify ( { meta : { } , features : [ { ... feature , name : 'firstUpdate' } ] } ) ,
1412
1421
} ) ;
1413
1422
const firstUpdate = repo . getToggles ( ) ;
1414
- t . deepEqual ( firstUpdate , [ feature ] ) ;
1423
+ t . deepEqual ( firstUpdate , [ { ... feature , name : 'firstUpdate' } ] ) ;
1415
1424
// @ts -expect-error
1416
1425
t . is ( repo . etag , undefined ) ;
1417
1426
@@ -1430,4 +1439,12 @@ test('Streaming', async (t) => {
1430
1439
t . is ( msg , 'some error' ) ;
1431
1440
} ) ;
1432
1441
eventSource . emit ( 'error' , 'some error' ) ;
1442
+
1443
+ // re-connect simulation
1444
+ eventSource . emit ( 'unleash-connected' , {
1445
+ type : 'unleash-connected' ,
1446
+ data : JSON . stringify ( { meta : { } , features : [ { ...feature , name : 'reconnectUpdate' } ] } ) ,
1447
+ } ) ;
1448
+ const reconnectUpdate = repo . getToggles ( ) ;
1449
+ t . deepEqual ( reconnectUpdate , [ { ...feature , name : 'reconnectUpdate' } ] ) ;
1433
1450
} ) ;
0 commit comments