@@ -22,6 +22,7 @@ function setupClient(
2222 requiresStart ?: boolean ;
2323 disableNetwork ?: boolean ;
2424 sendEvents ?: boolean ;
25+ initialContext ?: LDContext ;
2526 } ,
2627) {
2728 const logger = options ?. logger ?? {
@@ -46,6 +47,7 @@ function setupClient(
4647 getImplementationHooks : ( ) => [ ] ,
4748 credentialType : 'clientSideId' ,
4849 requiresStart : options ?. requiresStart ?? true ,
50+ initialContext : options ?. initialContext ,
4951 } ,
5052 ) ;
5153
@@ -97,8 +99,7 @@ describe('LDClientImpl.start()', () => {
9799
98100 it ( 'returns the same promise when called multiple times' , async ( ) => {
99101 const mockPlatform = setupStreamingPlatform ( ) ;
100- const { ldc } = setupClient ( mockPlatform ) ;
101- ldc . setInitialContext ( context ) ;
102+ const { ldc } = setupClient ( mockPlatform , { initialContext : context } ) ;
102103
103104 const promise1 = ldc . start ( ) ;
104105 const promise2 = ldc . start ( ) ;
@@ -115,8 +116,7 @@ describe('LDClientImpl.start()', () => {
115116
116117 it ( 'returns cached result after initialization completes' , async ( ) => {
117118 const mockPlatform = setupStreamingPlatform ( ) ;
118- const { ldc } = setupClient ( mockPlatform ) ;
119- ldc . setInitialContext ( context ) ;
119+ const { ldc } = setupClient ( mockPlatform , { initialContext : context } ) ;
120120
121121 const result1 = await ldc . start ( ) ;
122122 expect ( result1 . status ) . toBe ( 'complete' ) ;
@@ -127,17 +127,15 @@ describe('LDClientImpl.start()', () => {
127127
128128 it ( 'resolves with complete status on successful identify' , async ( ) => {
129129 const mockPlatform = setupStreamingPlatform ( ) ;
130- const { ldc } = setupClient ( mockPlatform ) ;
131- ldc . setInitialContext ( context ) ;
130+ const { ldc } = setupClient ( mockPlatform , { initialContext : context } ) ;
132131
133132 const result = await ldc . start ( ) ;
134133 expect ( result . status ) . toBe ( 'complete' ) ;
135134 } ) ;
136135
137136 it ( 'sets the active context after start completes' , async ( ) => {
138137 const mockPlatform = setupStreamingPlatform ( ) ;
139- const { ldc } = setupClient ( mockPlatform ) ;
140- ldc . setInitialContext ( context ) ;
138+ const { ldc } = setupClient ( mockPlatform , { initialContext : context } ) ;
141139
142140 expect ( ldc . getContext ( ) ) . toBeUndefined ( ) ;
143141 await ldc . start ( ) ;
@@ -147,8 +145,7 @@ describe('LDClientImpl.start()', () => {
147145 describe ( 'bootstrap data' , ( ) => {
148146 it ( 'presets flags from bootstrap in identifyOptions' , async ( ) => {
149147 const mockPlatform = createBasicPlatform ( ) ;
150- const { ldc } = setupClient ( mockPlatform , { disableNetwork : true } ) ;
151- ldc . setInitialContext ( context ) ;
148+ const { ldc } = setupClient ( mockPlatform , { disableNetwork : true , initialContext : context } ) ;
152149
153150 await ldc . start ( {
154151 identifyOptions : { bootstrap : goodBootstrapData } ,
@@ -162,8 +159,7 @@ describe('LDClientImpl.start()', () => {
162159
163160 it ( 'presets flags from top-level bootstrap option' , async ( ) => {
164161 const mockPlatform = createBasicPlatform ( ) ;
165- const { ldc } = setupClient ( mockPlatform , { disableNetwork : true } ) ;
166- ldc . setInitialContext ( context ) ;
162+ const { ldc } = setupClient ( mockPlatform , { disableNetwork : true , initialContext : context } ) ;
167163
168164 await ldc . start ( { bootstrap : goodBootstrapData } ) ;
169165
@@ -174,8 +170,7 @@ describe('LDClientImpl.start()', () => {
174170
175171 it ( 'makes flags available synchronously before identify completes' , async ( ) => {
176172 const mockPlatform = createBasicPlatform ( ) ;
177- const { ldc } = setupClient ( mockPlatform , { disableNetwork : true } ) ;
178- ldc . setInitialContext ( context ) ;
173+ const { ldc } = setupClient ( mockPlatform , { disableNetwork : true , initialContext : context } ) ;
179174
180175 const startPromise = ldc . start ( {
181176 identifyOptions : { bootstrap : goodBootstrapDataWithReasons } ,
@@ -190,8 +185,7 @@ describe('LDClientImpl.start()', () => {
190185
191186 it ( 'supports bootstrap data with evaluation reasons' , async ( ) => {
192187 const mockPlatform = createBasicPlatform ( ) ;
193- const { ldc } = setupClient ( mockPlatform , { disableNetwork : true } ) ;
194- ldc . setInitialContext ( context ) ;
188+ const { ldc } = setupClient ( mockPlatform , { disableNetwork : true , initialContext : context } ) ;
195189
196190 await ldc . start ( {
197191 identifyOptions : { bootstrap : goodBootstrapDataWithReasons } ,
@@ -206,8 +200,7 @@ describe('LDClientImpl.start()', () => {
206200
207201 it ( 'prefers identifyOptions.bootstrap over top-level bootstrap' , async ( ) => {
208202 const mockPlatform = createBasicPlatform ( ) ;
209- const { ldc } = setupClient ( mockPlatform , { disableNetwork : true } ) ;
210- ldc . setInitialContext ( context ) ;
203+ const { ldc } = setupClient ( mockPlatform , { disableNetwork : true , initialContext : context } ) ;
211204
212205 const differentBootstrap = {
213206 'other-flag' : true ,
@@ -229,8 +222,7 @@ describe('LDClientImpl.start()', () => {
229222 const readFlagsFromBootstrapSpy = jest . spyOn ( bootstrapModule , 'readFlagsFromBootstrap' ) ;
230223
231224 const mockPlatform = createBasicPlatform ( ) ;
232- const { ldc } = setupClient ( mockPlatform , { disableNetwork : true } ) ;
233- ldc . setInitialContext ( context ) ;
225+ const { ldc } = setupClient ( mockPlatform , { disableNetwork : true , initialContext : context } ) ;
234226
235227 await ldc . start ( {
236228 identifyOptions : { bootstrap : goodBootstrapDataWithReasons } ,
@@ -249,8 +241,10 @@ describe('LDClientImpl.start()', () => {
249241 describe ( 'requiresStart guard' , ( ) => {
250242 it ( 'blocks identify before start when requiresStart is true' , async ( ) => {
251243 const mockPlatform = setupStreamingPlatform ( ) ;
252- const { ldc, logger } = setupClient ( mockPlatform , { requiresStart : true } ) ;
253- ldc . setInitialContext ( context ) ;
244+ const { ldc, logger } = setupClient ( mockPlatform , {
245+ requiresStart : true ,
246+ initialContext : context ,
247+ } ) ;
254248
255249 const result = await ldc . identifyResult ( { kind : 'user' , key : 'other-user' } ) ;
256250
@@ -265,8 +259,7 @@ describe('LDClientImpl.start()', () => {
265259
266260 it ( 'allows identify after start when requiresStart is true' , async ( ) => {
267261 const mockPlatform = setupStreamingPlatform ( ) ;
268- const { ldc } = setupClient ( mockPlatform , { requiresStart : true } ) ;
269- ldc . setInitialContext ( context ) ;
262+ const { ldc } = setupClient ( mockPlatform , { requiresStart : true , initialContext : context } ) ;
270263
271264 await ldc . start ( ) ;
272265
@@ -284,8 +277,7 @@ describe('LDClientImpl.start()', () => {
284277
285278 it ( 'defaults sheddable to true for post-start identifies when requiresStart is true' , async ( ) => {
286279 const mockPlatform = setupStreamingPlatform ( ) ;
287- const { ldc } = setupClient ( mockPlatform , { requiresStart : true } ) ;
288- ldc . setInitialContext ( context ) ;
280+ const { ldc } = setupClient ( mockPlatform , { requiresStart : true , initialContext : context } ) ;
289281
290282 const startPromise = ldc . start ( ) ;
291283 const promise1 = ldc . identifyResult ( { kind : 'user' , key : 'user-1' } ) ;
@@ -324,8 +316,7 @@ describe('LDClientImpl.start()', () => {
324316 describe ( 'waitForInitialization integration' , ( ) => {
325317 it ( 'resolves waitForInitialization when start completes' , async ( ) => {
326318 const mockPlatform = setupStreamingPlatform ( ) ;
327- const { ldc } = setupClient ( mockPlatform ) ;
328- ldc . setInitialContext ( context ) ;
319+ const { ldc } = setupClient ( mockPlatform , { initialContext : context } ) ;
329320
330321 const waitPromise = ldc . waitForInitialization ( { timeout : 10 } ) ;
331322 const startPromise = ldc . start ( ) ;
0 commit comments