11/* eslint-disable jest/no-conditional-expect */ 
22import  {  OpenFeatureSplitProvider  }  from  '../../lib/js-split-provider' ; 
3- import  {  getLocalHostSplitClient  }  from  '../testUtils' ; 
3+ import  {  getLocalHostSplitClient ,   getSplitFactory  }  from  '../testUtils' ; 
44
55import  {  OpenFeature  }  from  '@openfeature/server-sdk' ; 
66
7- describe ( 'client tests' ,  ( )  =>  { 
7+ const  cases  =  [ 
8+   [ 
9+     'openfeature client tests mode: splitClient' , 
10+     ( )  =>  ( {  splitClient : getLocalHostSplitClient ( ) } ) , 
11+     
12+   ] , 
13+   [ 
14+     'openfeature client tests mode: splitFactory' , 
15+     getSplitFactory 
16+   ] , 
17+ ] ; 
18+ 
19+ describe . each ( cases ) ( '%s' ,  ( label ,  getOptions )  =>  { 
820
921  let  client ; 
10-   let  splitClient ; 
1122  let  provider ; 
23+   let  options ; 
1224
1325  beforeEach ( ( )  =>  { 
14-     splitClient  =  getLocalHostSplitClient ( ) ; 
15-     provider  =  new  OpenFeatureSplitProvider ( {  splitClient } ) ; 
1626
27+     options  =  getOptions ( ) ; 
28+     provider  =  new  OpenFeatureSplitProvider ( options ) ; 
1729    OpenFeature . setProvider ( provider ) ; 
1830
1931    client  =  OpenFeature . getClient ( 'test' ) ; 
@@ -22,9 +34,8 @@ describe('client tests', () => {
2234    } ; 
2335    client . setContext ( evaluationContext ) ; 
2436  } ) ; 
25-   afterEach ( ( )  =>  { 
26-     splitClient . destroy ( ) ; 
27-     provider  =  undefined ; 
37+   afterEach ( async  ( )  =>  { 
38+     await  OpenFeature . close ( ) ; 
2839  } ) ; 
2940
3041  test ( 'use default test' ,  async  ( )  =>  { 
@@ -206,13 +217,13 @@ describe('client tests', () => {
206217  } ) ; 
207218
208219  test ( 'track: without value' ,  async  ( )  =>  { 
209-     const  trackSpy  =  jest . spyOn ( splitClient ,  'track' ) ; 
220+     const  trackSpy  =  jest . spyOn ( options . splitClient  ?  options . splitClient  :  options . client ( ) ,  'track' ) ; 
210221    await  client . track ( 'my-event' ,  {  targetingKey : 'u1' ,  trafficType : 'user'  } ,  {  properties : {  prop1 : 'value1'  }  } ) ; 
211222    expect ( trackSpy ) . toHaveBeenCalledWith ( 'u1' ,  'user' ,  'my-event' ,  undefined ,  {   prop1 : 'value1'  } ) ; 
212223  } ) ; 
213224
214225  test ( 'track: with value' ,  async  ( )  =>  { 
215-     const  trackSpy  =  jest . spyOn ( splitClient ,  'track' ) ; 
226+     const  trackSpy  =  jest . spyOn ( options . splitClient  ?  options . splitClient  :  options . client ( ) ,  'track' ) ; 
216227    await  client . track ( 'my-event' ,  {  targetingKey : 'u1' ,  trafficType : 'user'  } ,  {  value : 9.99 ,  properties : {  prop1 : 'value1'  }  } ) ; 
217228    expect ( trackSpy ) . toHaveBeenCalledWith ( 'u1' ,  'user' ,  'my-event' ,  9.99 ,  {   prop1 : 'value1'  } ) ; 
218229  } ) ; 
0 commit comments