@@ -1355,17 +1355,20 @@ describe("ConfigCatClient", () => {
1355
1355
for ( const addListenersViaOptions of [ false , true ] ) {
1356
1356
it ( `ConfigCatClient should emit events, which listeners added ${ addListenersViaOptions ? "via options" : "directly on the client" } should get notified of` , async ( ) => {
1357
1357
let clientReadyEventCount = 0 ;
1358
+ const configFetchedEvents : [ RefreshResult , boolean ] [ ] = [ ] ;
1358
1359
const configChangedEvents : IConfig [ ] = [ ] ;
1359
1360
const flagEvaluatedEvents : IEvaluationDetails [ ] = [ ] ;
1360
1361
const errorEvents : [ string , any ] [ ] = [ ] ;
1361
1362
1362
1363
const handleClientReady = ( ) => clientReadyEventCount ++ ;
1364
+ const handleConfigFetched = ( result : RefreshResult , isInitiatedByUser : boolean ) => configFetchedEvents . push ( [ result , isInitiatedByUser ] ) ;
1363
1365
const handleConfigChanged = ( pc : IConfig ) => configChangedEvents . push ( pc ) ;
1364
1366
const handleFlagEvaluated = ( ed : IEvaluationDetails ) => flagEvaluatedEvents . push ( ed ) ;
1365
1367
const handleClientError = ( msg : string , err : any ) => errorEvents . push ( [ msg , err ] ) ;
1366
1368
1367
1369
function setupHooks ( hooks : IProvidesHooks ) {
1368
1370
hooks . on ( "clientReady" , handleClientReady ) ;
1371
+ hooks . on ( "configFetched" , handleConfigFetched ) ;
1369
1372
hooks . on ( "configChanged" , handleConfigChanged ) ;
1370
1373
hooks . on ( "flagEvaluated" , handleFlagEvaluated ) ;
1371
1374
hooks . on ( "clientError" , handleClientError ) ;
@@ -1391,6 +1394,7 @@ describe("ConfigCatClient", () => {
1391
1394
1392
1395
assert . equal ( state , ClientCacheState . NoFlagData ) ;
1393
1396
assert . equal ( clientReadyEventCount , 1 ) ;
1397
+ assert . equal ( configFetchedEvents . length , 0 ) ;
1394
1398
assert . equal ( configChangedEvents . length , 0 ) ;
1395
1399
assert . equal ( flagEvaluatedEvents . length , 0 ) ;
1396
1400
assert . equal ( errorEvents . length , 0 ) ;
@@ -1410,6 +1414,7 @@ describe("ConfigCatClient", () => {
1410
1414
1411
1415
await client . forceRefreshAsync ( ) ;
1412
1416
1417
+ assert . equal ( configFetchedEvents . length , 0 ) ;
1413
1418
assert . equal ( configChangedEvents . length , 0 ) ;
1414
1419
assert . equal ( errorEvents . length , 1 ) ;
1415
1420
const [ actualErrorMessage , actualErrorException ] = errorEvents [ 0 ] ;
@@ -1422,6 +1427,10 @@ describe("ConfigCatClient", () => {
1422
1427
await client . forceRefreshAsync ( ) ;
1423
1428
const cachedPc = await configCache . get ( "" ) ;
1424
1429
1430
+ assert . equal ( configFetchedEvents . length , 1 ) ;
1431
+ const [ refreshResult , isInitiatedByUser ] = configFetchedEvents [ 0 ] ;
1432
+ assert . isTrue ( isInitiatedByUser ) ;
1433
+ assert . isTrue ( refreshResult . isSuccess ) ;
1425
1434
assert . equal ( configChangedEvents . length , 1 ) ;
1426
1435
assert . strictEqual ( configChangedEvents [ 0 ] , cachedPc . config ) ;
1427
1436
@@ -1438,6 +1447,7 @@ describe("ConfigCatClient", () => {
1438
1447
// 5. Client gets disposed
1439
1448
client . dispose ( ) ;
1440
1449
1450
+ assert . equal ( configFetchedEvents . length , 1 ) ;
1441
1451
assert . equal ( clientReadyEventCount , 1 ) ;
1442
1452
assert . equal ( configChangedEvents . length , 1 ) ;
1443
1453
assert . equal ( evaluationDetails . length , flagEvaluatedEvents . length ) ;
0 commit comments