|
1 | 1 | import { AutoEnvAttributes, clone, Hasher, LDLogger } from '@launchdarkly/js-sdk-common'; |
2 | 2 |
|
3 | 3 | import { LDContext } from '../src/api/LDContext'; |
| 4 | +import * as bootstrapModule from '../src/flag-manager/bootstrap'; |
4 | 5 | import LDClientImpl from '../src/LDClientImpl'; |
5 | 6 | import { Flags } from '../src/types'; |
6 | 7 | import { createBasicPlatform } from './createBasicPlatform'; |
@@ -223,6 +224,26 @@ describe('LDClientImpl.start()', () => { |
223 | 224 | expect(flags['other-flag']).toBe(true); |
224 | 225 | expect(flags.killswitch).toBeUndefined(); |
225 | 226 | }); |
| 227 | + |
| 228 | + it('parses bootstrap data only once when using start()', async () => { |
| 229 | + const readFlagsFromBootstrapSpy = jest.spyOn(bootstrapModule, 'readFlagsFromBootstrap'); |
| 230 | + |
| 231 | + const mockPlatform = createBasicPlatform(); |
| 232 | + const { ldc } = setupClient(mockPlatform, { disableNetwork: true }); |
| 233 | + ldc.setInitialContext(context); |
| 234 | + |
| 235 | + await ldc.start({ |
| 236 | + identifyOptions: { bootstrap: goodBootstrapDataWithReasons }, |
| 237 | + }); |
| 238 | + |
| 239 | + expect(readFlagsFromBootstrapSpy).toHaveBeenCalledTimes(1); |
| 240 | + expect(readFlagsFromBootstrapSpy).toHaveBeenCalledWith( |
| 241 | + expect.anything(), |
| 242 | + goodBootstrapDataWithReasons, |
| 243 | + ); |
| 244 | + |
| 245 | + readFlagsFromBootstrapSpy.mockRestore(); |
| 246 | + }); |
226 | 247 | }); |
227 | 248 |
|
228 | 249 | describe('requiresStart guard', () => { |
|
0 commit comments