Skip to content

Commit 0de87c1

Browse files
committed
chore: PR comments
1 parent 893fe09 commit 0de87c1

2 files changed

Lines changed: 21 additions & 25 deletions

File tree

packages/sdk/browser/__tests__/BrowserClient.test.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -246,31 +246,6 @@ describe('given a mock platform for a BrowserClient', () => {
246246
expect(client.getContext()).toEqual({ kind: 'user', key: 'bob' });
247247
});
248248

249-
it('parses bootstrap data when start is called with bootstrap', async () => {
250-
const client = makeClient(
251-
'client-side-id',
252-
{ kind: 'user', key: 'bob' },
253-
AutoEnvAttributes.Disabled,
254-
{
255-
streaming: false,
256-
logger,
257-
diagnosticOptOut: true,
258-
},
259-
platform,
260-
);
261-
262-
await client.start({
263-
identifyOptions: {
264-
bootstrap: goodBootstrapDataWithReasons,
265-
},
266-
});
267-
268-
// Verify that bootstrap data was parsed and flags are available.
269-
expect(client.allFlags().killswitch).toBe(true);
270-
expect(client.allFlags()['string-flag']).toBe('is bob');
271-
expect(client.allFlags().cat).toBe(false);
272-
});
273-
274249
it('uses the latest bootstrap data when identify is called with new bootstrap data', async () => {
275250
const initialBootstrapData = {
276251
'string-flag': 'is bob',

packages/shared/sdk-client/__tests__/LDClientImpl.start.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AutoEnvAttributes, clone, Hasher, LDLogger } from '@launchdarkly/js-sdk-common';
22

33
import { LDContext } from '../src/api/LDContext';
4+
import * as bootstrapModule from '../src/flag-manager/bootstrap';
45
import LDClientImpl from '../src/LDClientImpl';
56
import { Flags } from '../src/types';
67
import { createBasicPlatform } from './createBasicPlatform';
@@ -223,6 +224,26 @@ describe('LDClientImpl.start()', () => {
223224
expect(flags['other-flag']).toBe(true);
224225
expect(flags.killswitch).toBeUndefined();
225226
});
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+
});
226247
});
227248

228249
describe('requiresStart guard', () => {

0 commit comments

Comments
 (0)