@@ -2,14 +2,15 @@ import { EventEmitter } from 'node:events';
22import { get } from 'svelte/store' ;
33import { afterEach , beforeEach , describe , expect , it , Mock , vi } from 'vitest' ;
44
5- import { initialize , LDClient } from '@launchdarkly/js-client-sdk' ;
5+ import { initialize , LDClient } from '@launchdarkly/js-client-sdk/compat ' ;
66
77import { LD } from '../../../src/lib/client/SvelteLDClient' ;
88
9- vi . mock ( '@launchdarkly/js-client-sdk' , { spy : true } ) ;
9+ vi . mock ( '@launchdarkly/js-client-sdk/compat ' , { spy : true } ) ;
1010
1111const clientSideID = 'test-client-side-id' ;
1212const rawFlags = { 'test-flag' : true , 'another-test-flag' : 'flag-value' } ;
13+ const mockContext = { key : 'user1' } ;
1314
1415// used to mock ready and change events on the LDClient
1516const mockLDEventEmitter = new EventEmitter ( ) ;
@@ -62,7 +63,7 @@ describe('launchDarkly', () => {
6263
6364 it ( 'should set the loading status to false when the client is ready' , async ( ) => {
6465 const { initializing } = ld ;
65- ld . initialize ( clientSideID ) ;
66+ ld . initialize ( clientSideID , mockContext ) ;
6667
6768 expect ( get ( initializing ) ) . toBe ( true ) ; // should be true before the ready event is emitted
6869 mockLDEventEmitter . emit ( 'ready' ) ;
@@ -71,16 +72,16 @@ describe('launchDarkly', () => {
7172 } ) ;
7273
7374 it ( 'should initialize the LaunchDarkly SDK instance' , ( ) => {
74- ld . initialize ( clientSideID ) ;
75+ ld . initialize ( clientSideID , mockContext ) ;
7576
76- expect ( initialize ) . toHaveBeenCalledWith ( 'test-client-side-id' ) ;
77+ expect ( initialize ) . toHaveBeenCalledWith ( 'test-client-side-id' , mockContext ) ;
7778 } ) ;
7879
7980 it ( 'should register function that gets flag values when client is ready' , ( ) => {
8081 const newFlags = { ...rawFlags , 'new-flag' : true } ;
8182 const allFlagsSpy = vi . spyOn ( mockLDClient , 'allFlags' ) . mockReturnValue ( newFlags ) ;
8283
83- ld . initialize ( clientSideID ) ;
84+ ld . initialize ( clientSideID , mockContext ) ;
8485 mockLDEventEmitter . emit ( 'ready' ) ;
8586
8687 expect ( allFlagsSpy ) . toHaveBeenCalledOnce ( ) ;
@@ -91,7 +92,7 @@ describe('launchDarkly', () => {
9192 const changedFlags = { ...rawFlags , 'changed-flag' : true } ;
9293 const allFlagsSpy = vi . spyOn ( mockLDClient , 'allFlags' ) . mockReturnValue ( changedFlags ) ;
9394
94- ld . initialize ( clientSideID ) ;
95+ ld . initialize ( clientSideID , mockContext ) ;
9596 mockLDEventEmitter . emit ( 'change' ) ;
9697
9798 expect ( allFlagsSpy ) . toHaveBeenCalledOnce ( ) ;
@@ -116,7 +117,7 @@ describe('launchDarkly', () => {
116117
117118 it ( 'should return a derived store that reflects the value of the specified flag' , ( ) => {
118119 const flagKey = 'test-flag' ;
119- ld . initialize ( clientSideID ) ;
120+ ld . initialize ( clientSideID , mockContext ) ;
120121
121122 const flagStore = ld . watch ( flagKey ) ;
122123
@@ -126,7 +127,7 @@ describe('launchDarkly', () => {
126127 it ( 'should update the flag store when the flag value changes' , ( ) => {
127128 const booleanFlagKey = 'test-flag' ;
128129 const stringFlagKey = 'another-test-flag' ;
129- ld . initialize ( clientSideID ) ;
130+ ld . initialize ( clientSideID , mockContext ) ;
130131 const flagStore = ld . watch ( booleanFlagKey ) ;
131132 const flagStore2 = ld . watch ( stringFlagKey ) ;
132133
@@ -153,7 +154,7 @@ describe('launchDarkly', () => {
153154
154155 it ( 'should return undefined if the flag is not found' , ( ) => {
155156 const flagKey = 'non-existent-flag' ;
156- ld . initialize ( clientSideID ) ;
157+ ld . initialize ( clientSideID , mockContext ) ;
157158
158159 const flagStore = ld . watch ( flagKey ) ;
159160
0 commit comments