Skip to content

Commit 9c50629

Browse files
prepare 3.2.7 release (#22)
1 parent 0d1b430 commit 9c50629

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

src/__tests__/LDClient-events-test.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as messages from '../messages';
22

3-
import { withCloseable } from 'launchdarkly-js-test-helpers';
3+
import { withCloseable, sleepAsync } from 'launchdarkly-js-test-helpers';
44

55
import { respond, respondJson } from './mockHttp';
66
import * as stubPlatform from './stubPlatform';
@@ -426,6 +426,28 @@ describe('LDClient events', () => {
426426
});
427427
});
428428

429+
async function expectDiagnosticEventAndDiscardRegularEvent(server) {
430+
const req0 = await server.nextRequest();
431+
const req1 = await server.nextRequest();
432+
const expectedPath = '/events/diagnostic/' + envName;
433+
const otherPath = '/events/bulk/' + envName;
434+
let initEventReq;
435+
if (req0.path === expectedPath) {
436+
expect(req1.path).toEqual(otherPath);
437+
initEventReq = req0;
438+
} else {
439+
expect(req0.path).toEqual(otherPath);
440+
expect(req1.path).toEqual(expectedPath);
441+
initEventReq = req1;
442+
}
443+
return JSON.parse(initEventReq.body);
444+
}
445+
446+
async function expectNoMoreRequests(server, timeout) {
447+
await sleepAsync(timeout);
448+
expect(server.requests.length()).toEqual(0);
449+
}
450+
429451
it('sends diagnostic init event on startup', async () => {
430452
const server = platform.testing.http.newServer();
431453
server.byDefault(respond(202));
@@ -439,15 +461,11 @@ describe('LDClient events', () => {
439461
await withCloseable(client, async () => {
440462
await client.waitForInitialization();
441463
await client.flush();
442-
const req0 = await server.nextRequest();
443-
const req1 = await server.nextRequest();
444-
const expectedPath = '/events/diagnostic/' + envName;
445-
expect([req0.path, req1.path]).toContain(expectedPath);
446-
const req = req0.path === expectedPath ? req0 : req1;
447-
const data = JSON.parse(req.body);
464+
const data = await expectDiagnosticEventAndDiscardRegularEvent(server);
448465
expect(data.kind).toEqual('diagnostic-init');
449466
expect(data.platform).toEqual(platform.diagnosticPlatformData);
450467
expect(data.sdk).toEqual(platform.diagnosticSdkData);
468+
await expectNoMoreRequests(server, 50);
451469
});
452470
});
453471
});
@@ -467,15 +485,11 @@ describe('LDClient events', () => {
467485
await withCloseable(client, async () => {
468486
await client.waitForInitialization();
469487
await client.flush();
470-
const req0 = await server.nextRequest();
471-
const req1 = await server.nextRequest();
472-
const expectedPath = '/events/diagnostic/' + envName;
473-
expect([req0.path, req1.path]).toContain(expectedPath);
474-
const req = req0.path === expectedPath ? req0 : req1;
475-
const data = JSON.parse(req.body);
488+
const data = await expectDiagnosticEventAndDiscardRegularEvent(server);
476489
expect(data.kind).toEqual('diagnostic-combined');
477490
expect(data.platform).toEqual(platform1.diagnosticPlatformData);
478491
expect(data.sdk).toEqual(platform1.diagnosticSdkData);
492+
await expectNoMoreRequests(server, 50);
479493
});
480494
});
481495
});
@@ -497,6 +511,7 @@ describe('LDClient events', () => {
497511
expect(server.requests.length()).toEqual(1);
498512
const req = await server.nextRequest();
499513
expect(req.path).toEqual('/events/bulk/' + envName);
514+
await expectNoMoreRequests(server, 50);
500515
});
501516
});
502517
});

src/__tests__/stubPlatform.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ export function defaults() {
8383

8484
makeClient: (env, user, options = {}) => {
8585
const config = { logger: p.testing.logger, ...options };
86-
return LDClient.initialize(env, user, config, p).client;
86+
// We want to simulate what the platform-specific SDKs will do in their own initialization functions.
87+
// They will call the common package's LDClient.initialize() and receive the clientVars object which
88+
// contains both the underlying client (in its "client" property) and some internal methods that the
89+
// platform-specific SDKs can use to do internal stuff. One of those is start(), which they will
90+
// call after doing any other initialization things they may need to do.
91+
const clientVars = LDClient.initialize(env, user, config, p);
92+
clientVars.start();
93+
return clientVars.client;
8794
},
8895

8996
setCurrentUrl: url => {

src/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ export function initialize(env, user, specifiedOptions, platform, extraOptionDef
4343
const diagnosticsManager = diagnosticsEnabled
4444
? diagnostics.DiagnosticsManager(platform, diagnosticsAccumulator, eventSender, environment, options, diagnosticId)
4545
: null;
46-
if (diagnosticsManager) {
47-
diagnosticsManager.start();
48-
}
4946

5047
const stream = Stream(platform, options, environment, diagnosticsAccumulator);
5148

0 commit comments

Comments
 (0)