launchdarkly-js-sdk-common 5.0.3 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/CODEOWNERS +2 -0
- package/README.md +2 -2
- package/SECURITY.md +5 -0
- package/package.json +4 -3
- package/src/ContextFilter.js +17 -12
- package/src/EventProcessor.js +4 -2
- package/src/EventSender.js +6 -30
- package/src/__tests__/ContextFilter-test.js +33 -0
- package/src/__tests__/EventProcessor-test.js +8 -5
- package/src/__tests__/EventSender-test.js +14 -70
- package/src/__tests__/EventSummarizer-test.js +4 -1
- package/src/__tests__/LDClient-events-test.js +41 -29
- package/src/__tests__/LDClient-localstorage-test.js +8 -8
- package/src/__tests__/LDClient-streaming-test.js +41 -41
- package/src/__tests__/LDClient-test.js +37 -37
- package/src/__tests__/LDClient-timeout-test.js +90 -0
- package/src/__tests__/diagnosticEvents-test.js +8 -2
- package/src/__tests__/stubPlatform.js +0 -4
- package/src/__tests__/testUtils.js +1 -1
- package/src/__tests__/utils-test.js +1 -12
- package/src/errors.js +2 -0
- package/src/headers.js +2 -2
- package/src/index.js +40 -1
- package/src/messages.js +4 -0
- package/src/timedPromise.js +17 -0
- package/src/utils.js +0 -41
- package/test-types.ts +1 -1
- package/typings.d.ts +81 -71
|
@@ -61,7 +61,7 @@ describe('LDClient streaming', () => {
|
|
|
61
61
|
|
|
62
62
|
it('does not connect to the stream by default', async () => {
|
|
63
63
|
await withClientAndServer({}, async client => {
|
|
64
|
-
await client.waitForInitialization();
|
|
64
|
+
await client.waitForInitialization(5);
|
|
65
65
|
|
|
66
66
|
expectNoStreamIsOpen();
|
|
67
67
|
});
|
|
@@ -69,7 +69,7 @@ describe('LDClient streaming', () => {
|
|
|
69
69
|
|
|
70
70
|
it('connects to the stream if options.streaming is true', async () => {
|
|
71
71
|
await withClientAndServer({ streaming: true }, async client => {
|
|
72
|
-
await client.waitForInitialization();
|
|
72
|
+
await client.waitForInitialization(5);
|
|
73
73
|
|
|
74
74
|
await platform.testing.expectStream(fullStreamUrlWithUser);
|
|
75
75
|
});
|
|
@@ -78,7 +78,7 @@ describe('LDClient streaming', () => {
|
|
|
78
78
|
describe('setStreaming()', () => {
|
|
79
79
|
it('can connect to the stream', async () => {
|
|
80
80
|
await withClientAndServer({}, async client => {
|
|
81
|
-
await client.waitForInitialization();
|
|
81
|
+
await client.waitForInitialization(5);
|
|
82
82
|
|
|
83
83
|
client.setStreaming(true);
|
|
84
84
|
await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -87,7 +87,7 @@ describe('LDClient streaming', () => {
|
|
|
87
87
|
|
|
88
88
|
it('can disconnect from the stream', async () => {
|
|
89
89
|
await withClientAndServer({}, async client => {
|
|
90
|
-
await client.waitForInitialization();
|
|
90
|
+
await client.waitForInitialization(5);
|
|
91
91
|
|
|
92
92
|
client.setStreaming(true);
|
|
93
93
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -100,7 +100,7 @@ describe('LDClient streaming', () => {
|
|
|
100
100
|
describe('on("change")', () => {
|
|
101
101
|
it('connects to the stream if not otherwise overridden', async () => {
|
|
102
102
|
await withClientAndServer({}, async client => {
|
|
103
|
-
await client.waitForInitialization();
|
|
103
|
+
await client.waitForInitialization(5);
|
|
104
104
|
client.on('change', () => {});
|
|
105
105
|
|
|
106
106
|
await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -109,7 +109,7 @@ describe('LDClient streaming', () => {
|
|
|
109
109
|
|
|
110
110
|
it('also connects if listening for a specific flag', async () => {
|
|
111
111
|
await withClientAndServer({}, async client => {
|
|
112
|
-
await client.waitForInitialization();
|
|
112
|
+
await client.waitForInitialization(5);
|
|
113
113
|
client.on('change:flagkey', () => {});
|
|
114
114
|
|
|
115
115
|
await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -118,7 +118,7 @@ describe('LDClient streaming', () => {
|
|
|
118
118
|
|
|
119
119
|
it('does not connect if some other kind of event was specified', async () => {
|
|
120
120
|
await withClientAndServer({}, async client => {
|
|
121
|
-
await client.waitForInitialization();
|
|
121
|
+
await client.waitForInitialization(5);
|
|
122
122
|
client.on('error', () => {});
|
|
123
123
|
|
|
124
124
|
expectNoStreamIsOpen();
|
|
@@ -127,7 +127,7 @@ describe('LDClient streaming', () => {
|
|
|
127
127
|
|
|
128
128
|
it('does not connect if options.streaming is explicitly set to false', async () => {
|
|
129
129
|
await withClientAndServer({ streaming: false }, async client => {
|
|
130
|
-
await client.waitForInitialization();
|
|
130
|
+
await client.waitForInitialization(5);
|
|
131
131
|
client.on('change', () => {});
|
|
132
132
|
|
|
133
133
|
expectNoStreamIsOpen();
|
|
@@ -136,7 +136,7 @@ describe('LDClient streaming', () => {
|
|
|
136
136
|
|
|
137
137
|
it('does not connect if setStreaming(false) was called', async () => {
|
|
138
138
|
await withClientAndServer({}, async client => {
|
|
139
|
-
await client.waitForInitialization();
|
|
139
|
+
await client.waitForInitialization(5);
|
|
140
140
|
client.setStreaming(false);
|
|
141
141
|
client.on('change', () => {});
|
|
142
142
|
|
|
@@ -150,7 +150,7 @@ describe('LDClient streaming', () => {
|
|
|
150
150
|
await withClientAndServer({}, async client => {
|
|
151
151
|
const listener1 = () => {};
|
|
152
152
|
const listener2 = () => {};
|
|
153
|
-
await client.waitForInitialization();
|
|
153
|
+
await client.waitForInitialization(5);
|
|
154
154
|
|
|
155
155
|
client.on('change', listener1);
|
|
156
156
|
client.on('change:flagKey', listener2);
|
|
@@ -172,7 +172,7 @@ describe('LDClient streaming', () => {
|
|
|
172
172
|
await withClientAndServer({}, async client => {
|
|
173
173
|
const listener1 = allValues => changes1.push(allValues);
|
|
174
174
|
const listener2 = newValue => changes2.push(newValue);
|
|
175
|
-
await client.waitForInitialization();
|
|
175
|
+
await client.waitForInitialization(5);
|
|
176
176
|
|
|
177
177
|
client.setStreaming(true);
|
|
178
178
|
|
|
@@ -212,7 +212,7 @@ describe('LDClient streaming', () => {
|
|
|
212
212
|
|
|
213
213
|
it('passes the secure mode hash in the stream URL if provided', async () => {
|
|
214
214
|
await withClientAndServer({ hash }, async client => {
|
|
215
|
-
await client.waitForInitialization();
|
|
215
|
+
await client.waitForInitialization(5);
|
|
216
216
|
client.on('change:flagKey', () => {});
|
|
217
217
|
|
|
218
218
|
await expectStreamConnecting(fullStreamUrlWithUser + '?h=' + hash);
|
|
@@ -221,7 +221,7 @@ describe('LDClient streaming', () => {
|
|
|
221
221
|
|
|
222
222
|
it('passes withReasons parameter if provided', async () => {
|
|
223
223
|
await withClientAndServer({ evaluationReasons: true }, async client => {
|
|
224
|
-
await client.waitForInitialization();
|
|
224
|
+
await client.waitForInitialization(5);
|
|
225
225
|
client.setStreaming(true);
|
|
226
226
|
|
|
227
227
|
await expectStreamConnecting(fullStreamUrlWithUser + '?withReasons=true');
|
|
@@ -230,7 +230,7 @@ describe('LDClient streaming', () => {
|
|
|
230
230
|
|
|
231
231
|
it('passes secure mode hash and withReasons if provided', async () => {
|
|
232
232
|
await withClientAndServer({ hash, evaluationReasons: true }, async client => {
|
|
233
|
-
await client.waitForInitialization();
|
|
233
|
+
await client.waitForInitialization(5);
|
|
234
234
|
client.setStreaming(true);
|
|
235
235
|
|
|
236
236
|
await expectStreamConnecting(fullStreamUrlWithUser + '?h=' + hash + '&withReasons=true');
|
|
@@ -240,7 +240,7 @@ describe('LDClient streaming', () => {
|
|
|
240
240
|
it('handles stream ping message by getting flags', async () => {
|
|
241
241
|
await withClientAndServer({}, async (client, server) => {
|
|
242
242
|
server.byDefault(respondJson({ flagKey: { value: true, version: 1 } }));
|
|
243
|
-
await client.waitForInitialization();
|
|
243
|
+
await client.waitForInitialization(5);
|
|
244
244
|
client.setStreaming(true);
|
|
245
245
|
|
|
246
246
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -262,7 +262,7 @@ describe('LDClient streaming', () => {
|
|
|
262
262
|
reqRespQueue.add({ req: req, resp: resp });
|
|
263
263
|
});
|
|
264
264
|
|
|
265
|
-
const initPromise = client.waitForInitialization();
|
|
265
|
+
const initPromise = client.waitForInitialization(5);
|
|
266
266
|
const poll1 = await reqRespQueue.take();
|
|
267
267
|
expect(poll1.req.path).toContain(initUserBase64);
|
|
268
268
|
respondJson({ flagKey: { value: 1 } })(poll1.req, poll1.resp);
|
|
@@ -299,7 +299,7 @@ describe('LDClient streaming', () => {
|
|
|
299
299
|
|
|
300
300
|
it('handles stream put message by updating flags', async () => {
|
|
301
301
|
await withClientAndServer({}, async client => {
|
|
302
|
-
await client.waitForInitialization();
|
|
302
|
+
await client.waitForInitialization(5);
|
|
303
303
|
client.setStreaming(true);
|
|
304
304
|
|
|
305
305
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -315,7 +315,7 @@ describe('LDClient streaming', () => {
|
|
|
315
315
|
platform.testing.setLocalStorageImmediately(lsKey, '{"flagKey":false}');
|
|
316
316
|
|
|
317
317
|
await withClientAndServer({ bootstrap: 'localstorage' }, async client => {
|
|
318
|
-
await client.waitForInitialization();
|
|
318
|
+
await client.waitForInitialization(5);
|
|
319
319
|
client.setStreaming(true);
|
|
320
320
|
|
|
321
321
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -331,7 +331,7 @@ describe('LDClient streaming', () => {
|
|
|
331
331
|
|
|
332
332
|
it('fires global change event when flags are updated from put event', async () => {
|
|
333
333
|
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => {
|
|
334
|
-
await client.waitForInitialization();
|
|
334
|
+
await client.waitForInitialization(5);
|
|
335
335
|
|
|
336
336
|
const receivedChange = eventSink(client, 'change');
|
|
337
337
|
|
|
@@ -355,7 +355,7 @@ describe('LDClient streaming', () => {
|
|
|
355
355
|
},
|
|
356
356
|
};
|
|
357
357
|
await withClientAndServer(config, async client => {
|
|
358
|
-
await client.waitForInitialization();
|
|
358
|
+
await client.waitForInitialization(5);
|
|
359
359
|
|
|
360
360
|
const receivedChange = eventSink(client, 'change');
|
|
361
361
|
|
|
@@ -375,7 +375,7 @@ describe('LDClient streaming', () => {
|
|
|
375
375
|
|
|
376
376
|
it('fires individual change event when flags are updated from put event', async () => {
|
|
377
377
|
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => {
|
|
378
|
-
await client.waitForInitialization();
|
|
378
|
+
await client.waitForInitialization(5);
|
|
379
379
|
|
|
380
380
|
const receivedChange = eventSink(client, 'change:flagKey');
|
|
381
381
|
|
|
@@ -391,7 +391,7 @@ describe('LDClient streaming', () => {
|
|
|
391
391
|
|
|
392
392
|
it('handles patch message by updating flag', async () => {
|
|
393
393
|
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => {
|
|
394
|
-
await client.waitForInitialization();
|
|
394
|
+
await client.waitForInitialization(5);
|
|
395
395
|
client.setStreaming(true);
|
|
396
396
|
|
|
397
397
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -404,7 +404,7 @@ describe('LDClient streaming', () => {
|
|
|
404
404
|
it('does not update flag if patch version < flag version', async () => {
|
|
405
405
|
const initData = makeBootstrap({ flagKey: { value: 'a', version: 2 } });
|
|
406
406
|
await withClientAndServer({ bootstrap: initData }, async client => {
|
|
407
|
-
await client.waitForInitialization();
|
|
407
|
+
await client.waitForInitialization(5);
|
|
408
408
|
|
|
409
409
|
expect(client.variation('flagKey')).toEqual('a');
|
|
410
410
|
|
|
@@ -420,7 +420,7 @@ describe('LDClient streaming', () => {
|
|
|
420
420
|
it('does not update flag if patch version == flag version', async () => {
|
|
421
421
|
const initData = makeBootstrap({ flagKey: { value: 'a', version: 2 } });
|
|
422
422
|
await withClientAndServer({ bootstrap: initData }, async client => {
|
|
423
|
-
await client.waitForInitialization();
|
|
423
|
+
await client.waitForInitialization(5);
|
|
424
424
|
|
|
425
425
|
expect(client.variation('flagKey')).toEqual('a');
|
|
426
426
|
|
|
@@ -436,7 +436,7 @@ describe('LDClient streaming', () => {
|
|
|
436
436
|
it('updates flag if patch has a version and flag has no version', async () => {
|
|
437
437
|
const initData = makeBootstrap({ flagKey: { value: 'a' } });
|
|
438
438
|
await withClientAndServer({ bootstrap: initData }, async client => {
|
|
439
|
-
await client.waitForInitialization();
|
|
439
|
+
await client.waitForInitialization(5);
|
|
440
440
|
|
|
441
441
|
expect(client.variation('flagKey')).toEqual('a');
|
|
442
442
|
|
|
@@ -452,7 +452,7 @@ describe('LDClient streaming', () => {
|
|
|
452
452
|
it('updates flag if flag has a version and patch has no version', async () => {
|
|
453
453
|
const initData = makeBootstrap({ flagKey: { value: 'a', version: 2 } });
|
|
454
454
|
await withClientAndServer({ bootstrap: initData }, async client => {
|
|
455
|
-
await client.waitForInitialization();
|
|
455
|
+
await client.waitForInitialization(5);
|
|
456
456
|
|
|
457
457
|
expect(client.variation('flagKey')).toEqual('a');
|
|
458
458
|
|
|
@@ -469,7 +469,7 @@ describe('LDClient streaming', () => {
|
|
|
469
469
|
platform.testing.setLocalStorageImmediately(lsKey, '{"flagKey":false}');
|
|
470
470
|
|
|
471
471
|
await withClientAndServer({ bootstrap: 'localstorage' }, async client => {
|
|
472
|
-
await client.waitForInitialization();
|
|
472
|
+
await client.waitForInitialization(5);
|
|
473
473
|
client.setStreaming(true);
|
|
474
474
|
|
|
475
475
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -485,7 +485,7 @@ describe('LDClient streaming', () => {
|
|
|
485
485
|
|
|
486
486
|
it('fires global change event when flag is updated from patch event', async () => {
|
|
487
487
|
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => {
|
|
488
|
-
await client.waitForInitialization();
|
|
488
|
+
await client.waitForInitialization(5);
|
|
489
489
|
|
|
490
490
|
const receivedChange = eventSink(client, 'change');
|
|
491
491
|
|
|
@@ -503,7 +503,7 @@ describe('LDClient streaming', () => {
|
|
|
503
503
|
|
|
504
504
|
it('fires individual change event when flag is updated from patch event', async () => {
|
|
505
505
|
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => {
|
|
506
|
-
await client.waitForInitialization();
|
|
506
|
+
await client.waitForInitialization(5);
|
|
507
507
|
|
|
508
508
|
const receivedChange = eventSink(client, 'change:flagKey');
|
|
509
509
|
|
|
@@ -519,7 +519,7 @@ describe('LDClient streaming', () => {
|
|
|
519
519
|
|
|
520
520
|
it('fires global change event when flag is newly created from patch event', async () => {
|
|
521
521
|
await withClientAndServer({}, async client => {
|
|
522
|
-
await client.waitForInitialization();
|
|
522
|
+
await client.waitForInitialization(5);
|
|
523
523
|
|
|
524
524
|
const receivedChange = eventSink(client, 'change');
|
|
525
525
|
|
|
@@ -537,7 +537,7 @@ describe('LDClient streaming', () => {
|
|
|
537
537
|
|
|
538
538
|
it('fires individual change event when flag is newly created from patch event', async () => {
|
|
539
539
|
await withClientAndServer({}, async client => {
|
|
540
|
-
await client.waitForInitialization();
|
|
540
|
+
await client.waitForInitialization(5);
|
|
541
541
|
|
|
542
542
|
const receivedChange = eventSink(client, 'change:flagKey');
|
|
543
543
|
|
|
@@ -553,7 +553,7 @@ describe('LDClient streaming', () => {
|
|
|
553
553
|
|
|
554
554
|
it('handles delete message by deleting flag', async () => {
|
|
555
555
|
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => {
|
|
556
|
-
await client.waitForInitialization();
|
|
556
|
+
await client.waitForInitialization(5);
|
|
557
557
|
client.setStreaming(true);
|
|
558
558
|
|
|
559
559
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -567,7 +567,7 @@ describe('LDClient streaming', () => {
|
|
|
567
567
|
|
|
568
568
|
it('handles delete message for unknown flag by storing placeholder', async () => {
|
|
569
569
|
await withClientAndServer({}, async client => {
|
|
570
|
-
await client.waitForInitialization();
|
|
570
|
+
await client.waitForInitialization(5);
|
|
571
571
|
client.setStreaming(true);
|
|
572
572
|
|
|
573
573
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -587,7 +587,7 @@ describe('LDClient streaming', () => {
|
|
|
587
587
|
it('ignores delete message with lower version', async () => {
|
|
588
588
|
const initData = makeBootstrap({ flagKey: { value: 'yes', version: 3 } });
|
|
589
589
|
await withClientAndServer({ bootstrap: initData }, async client => {
|
|
590
|
-
await client.waitForInitialization();
|
|
590
|
+
await client.waitForInitialization(5);
|
|
591
591
|
client.setStreaming(true);
|
|
592
592
|
|
|
593
593
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -601,7 +601,7 @@ describe('LDClient streaming', () => {
|
|
|
601
601
|
|
|
602
602
|
it('fires global change event when flag is deleted', async () => {
|
|
603
603
|
await withClientAndServer({ bootstrap: { flagKey: true } }, async client => {
|
|
604
|
-
await client.waitForInitialization();
|
|
604
|
+
await client.waitForInitialization(5);
|
|
605
605
|
|
|
606
606
|
const receivedChange = eventSink(client, 'change');
|
|
607
607
|
|
|
@@ -619,7 +619,7 @@ describe('LDClient streaming', () => {
|
|
|
619
619
|
|
|
620
620
|
it('fires individual change event when flag is deleted', async () => {
|
|
621
621
|
await withClientAndServer({ bootstrap: { flagKey: true } }, async client => {
|
|
622
|
-
await client.waitForInitialization();
|
|
622
|
+
await client.waitForInitialization(5);
|
|
623
623
|
|
|
624
624
|
const receivedChange = eventSink(client, 'change:flagKey');
|
|
625
625
|
|
|
@@ -637,7 +637,7 @@ describe('LDClient streaming', () => {
|
|
|
637
637
|
platform.testing.setLocalStorageImmediately(lsKey, '{"flagKey":false}');
|
|
638
638
|
|
|
639
639
|
await withClientAndServer({ bootstrap: 'localstorage' }, async client => {
|
|
640
|
-
await client.waitForInitialization();
|
|
640
|
+
await client.waitForInitialization(5);
|
|
641
641
|
client.setStreaming(true);
|
|
642
642
|
|
|
643
643
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -655,7 +655,7 @@ describe('LDClient streaming', () => {
|
|
|
655
655
|
const doMalformedJsonEventTest = async (eventName, eventData) => {
|
|
656
656
|
// First, verify that there isn't an unhandled rejection if we're not listening for an error
|
|
657
657
|
await withClientAndServer({}, async client => {
|
|
658
|
-
await client.waitForInitialization();
|
|
658
|
+
await client.waitForInitialization(5);
|
|
659
659
|
client.setStreaming(true);
|
|
660
660
|
|
|
661
661
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -667,7 +667,7 @@ describe('LDClient streaming', () => {
|
|
|
667
667
|
const errorEvents = new AsyncQueue();
|
|
668
668
|
client.on('error', e => errorEvents.add(e));
|
|
669
669
|
|
|
670
|
-
await client.waitForInitialization();
|
|
670
|
+
await client.waitForInitialization(5);
|
|
671
671
|
client.setStreaming(true);
|
|
672
672
|
|
|
673
673
|
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
|
|
@@ -687,7 +687,7 @@ describe('LDClient streaming', () => {
|
|
|
687
687
|
const user2 = { key: 'user2' };
|
|
688
688
|
const encodedUser2 = 'eyJrZXkiOiJ1c2VyMiJ9';
|
|
689
689
|
await withClientAndServer({}, async client => {
|
|
690
|
-
await client.waitForInitialization();
|
|
690
|
+
await client.waitForInitialization(5);
|
|
691
691
|
client.setStreaming(true);
|
|
692
692
|
|
|
693
693
|
await expectStreamConnecting(makeExpectedStreamUrl(encodedUser));
|
|
@@ -703,7 +703,7 @@ describe('LDClient streaming', () => {
|
|
|
703
703
|
const newHash = hash + 'xxx';
|
|
704
704
|
|
|
705
705
|
await withClientAndServer({ hash }, async client => {
|
|
706
|
-
await client.waitForInitialization();
|
|
706
|
+
await client.waitForInitialization(5);
|
|
707
707
|
client.setStreaming(true);
|
|
708
708
|
|
|
709
709
|
await expectStreamConnecting(makeExpectedStreamUrl(encodedUser, hash));
|
|
@@ -64,7 +64,7 @@ describe('LDClient', () => {
|
|
|
64
64
|
it('resolves waitForInitialization promise', async () => {
|
|
65
65
|
await withServers(async baseConfig => {
|
|
66
66
|
await withClient(user, baseConfig, async client => {
|
|
67
|
-
await client.waitForInitialization();
|
|
67
|
+
await client.waitForInitialization(5);
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
});
|
|
@@ -82,7 +82,7 @@ describe('LDClient', () => {
|
|
|
82
82
|
await withServers(async (baseConfig, pollServer) => {
|
|
83
83
|
pollServer.byDefault(respondJson(flags));
|
|
84
84
|
await withClient(user, baseConfig, async client => {
|
|
85
|
-
await client.waitForInitialization();
|
|
85
|
+
await client.waitForInitialization(5);
|
|
86
86
|
|
|
87
87
|
const req = await pollServer.nextRequest();
|
|
88
88
|
expect(req.path).toMatch(/sdk\/eval/);
|
|
@@ -96,7 +96,7 @@ describe('LDClient', () => {
|
|
|
96
96
|
await withServers(async (baseConfig, pollServer) => {
|
|
97
97
|
pollServer.byDefault(respondJson(flags));
|
|
98
98
|
await withClient(user, { ...baseConfig, evaluationReasons: true }, async client => {
|
|
99
|
-
await client.waitForInitialization();
|
|
99
|
+
await client.waitForInitialization(5);
|
|
100
100
|
|
|
101
101
|
const req = await pollServer.nextRequest();
|
|
102
102
|
expect(req.path).toMatch(/sdk\/eval/);
|
|
@@ -108,7 +108,7 @@ describe('LDClient', () => {
|
|
|
108
108
|
async function verifyCustomHeader(sendLDHeaders, shouldGetHeaders) {
|
|
109
109
|
await withServers(async (baseConfig, pollServer) => {
|
|
110
110
|
await withClient(user, { ...baseConfig, sendLDHeaders }, async client => {
|
|
111
|
-
await client.waitForInitialization();
|
|
111
|
+
await client.waitForInitialization(5);
|
|
112
112
|
const request = await pollServer.nextRequest();
|
|
113
113
|
expect(request.headers['user-agent']).toEqual(
|
|
114
114
|
shouldGetHeaders ? utils.getLDUserAgentString(platform) : undefined
|
|
@@ -126,7 +126,7 @@ describe('LDClient', () => {
|
|
|
126
126
|
it('sanitizes the user', async () => {
|
|
127
127
|
await withServers(async baseConfig => {
|
|
128
128
|
await withClient(numericUser, baseConfig, async client => {
|
|
129
|
-
await client.waitForInitialization();
|
|
129
|
+
await client.waitForInitialization(5);
|
|
130
130
|
expect(client.getContext()).toEqual(stringifiedNumericUser);
|
|
131
131
|
});
|
|
132
132
|
});
|
|
@@ -137,14 +137,14 @@ describe('LDClient', () => {
|
|
|
137
137
|
await withServers(async baseConfig => {
|
|
138
138
|
let generatedUser;
|
|
139
139
|
await withClient(anonUser, baseConfig, async client0 => {
|
|
140
|
-
await client0.waitForInitialization();
|
|
140
|
+
await client0.waitForInitialization(5);
|
|
141
141
|
|
|
142
142
|
generatedUser = client0.getContext();
|
|
143
143
|
expect(generatedUser.key).toEqual(expect.anything());
|
|
144
144
|
expect(generatedUser).toMatchObject(anonUser);
|
|
145
145
|
});
|
|
146
146
|
await withClient(anonUser, baseConfig, async client1 => {
|
|
147
|
-
await client1.waitForInitialization();
|
|
147
|
+
await client1.waitForInitialization(5);
|
|
148
148
|
|
|
149
149
|
const newUser1 = client1.getContext();
|
|
150
150
|
expect(newUser1).toEqual(generatedUser);
|
|
@@ -159,7 +159,7 @@ describe('LDClient', () => {
|
|
|
159
159
|
await withServers(async baseConfig => {
|
|
160
160
|
let generatedUser;
|
|
161
161
|
await withClient(anonUser, baseConfig, async client0 => {
|
|
162
|
-
await client0.waitForInitialization();
|
|
162
|
+
await client0.waitForInitialization(5);
|
|
163
163
|
|
|
164
164
|
generatedUser = client0.getContext();
|
|
165
165
|
expect(generatedUser.key).toEqual(expect.anything());
|
|
@@ -167,7 +167,7 @@ describe('LDClient', () => {
|
|
|
167
167
|
});
|
|
168
168
|
await sleepAsync(100); // so that the time-based UUID algorithm will produce a different result below
|
|
169
169
|
await withClient(anonUser, baseConfig, async client1 => {
|
|
170
|
-
await client1.waitForInitialization();
|
|
170
|
+
await client1.waitForInitialization(5);
|
|
171
171
|
|
|
172
172
|
const newUser1 = client1.getContext();
|
|
173
173
|
expect(newUser1.key).toEqual(expect.anything());
|
|
@@ -192,7 +192,7 @@ describe('LDClient', () => {
|
|
|
192
192
|
|
|
193
193
|
it('rejects waitForInitialization promise', async () => {
|
|
194
194
|
await runTest(async client => {
|
|
195
|
-
await expect(client.waitForInitialization()).rejects.toThrow();
|
|
195
|
+
await expect(client.waitForInitialization(5)).rejects.toThrow();
|
|
196
196
|
});
|
|
197
197
|
});
|
|
198
198
|
|
|
@@ -263,7 +263,7 @@ describe('LDClient', () => {
|
|
|
263
263
|
it('should not fetch flag settings', async () => {
|
|
264
264
|
await withServers(async (baseConfig, pollServer) => {
|
|
265
265
|
await withClient(user, { ...baseConfig, bootstrap: {} }, async client => {
|
|
266
|
-
await client.waitForInitialization();
|
|
266
|
+
await client.waitForInitialization(5);
|
|
267
267
|
|
|
268
268
|
expect(pollServer.requests.length()).toEqual(0);
|
|
269
269
|
});
|
|
@@ -282,7 +282,7 @@ describe('LDClient', () => {
|
|
|
282
282
|
it('logs warning when bootstrap object uses old format', async () => {
|
|
283
283
|
const initData = { foo: 'bar' };
|
|
284
284
|
await withClient(user, { bootstrap: initData, sendEvents: false }, async client => {
|
|
285
|
-
await client.waitForInitialization();
|
|
285
|
+
await client.waitForInitialization(5);
|
|
286
286
|
|
|
287
287
|
expect(platform.testing.logger.output.warn).toEqual([messages.bootstrapOldFormat()]);
|
|
288
288
|
});
|
|
@@ -291,7 +291,7 @@ describe('LDClient', () => {
|
|
|
291
291
|
it('does not log warning when bootstrap object uses new format', async () => {
|
|
292
292
|
const initData = makeBootstrap({ foo: { value: 'bar', version: 1 } });
|
|
293
293
|
await withClient(user, { bootstrap: initData, sendEvents: false }, async client => {
|
|
294
|
-
await client.waitForInitialization();
|
|
294
|
+
await client.waitForInitialization(5);
|
|
295
295
|
|
|
296
296
|
expect(platform.testing.logger.output.warn).toEqual([]);
|
|
297
297
|
expect(client.variation('foo')).toEqual('bar');
|
|
@@ -306,7 +306,7 @@ describe('LDClient', () => {
|
|
|
306
306
|
sendEvents: false,
|
|
307
307
|
};
|
|
308
308
|
await withClient(user, config, async client => {
|
|
309
|
-
await client.waitForInitialization();
|
|
309
|
+
await client.waitForInitialization(5);
|
|
310
310
|
|
|
311
311
|
expect(client.variation('foo')).toEqual('bar');
|
|
312
312
|
});
|
|
@@ -318,7 +318,7 @@ describe('LDClient', () => {
|
|
|
318
318
|
sendEvents: false,
|
|
319
319
|
};
|
|
320
320
|
await withClient(user, config, async client => {
|
|
321
|
-
await client.waitForInitialization();
|
|
321
|
+
await client.waitForInitialization(5);
|
|
322
322
|
|
|
323
323
|
expect(client.variation('foo')).toEqual('bar');
|
|
324
324
|
});
|
|
@@ -329,7 +329,7 @@ describe('LDClient', () => {
|
|
|
329
329
|
await withServers(async (baseConfig, pollServer) => {
|
|
330
330
|
pollServer.byDefault(respondJson(flags));
|
|
331
331
|
await withClient(user, baseConfig, async client => {
|
|
332
|
-
await client.waitForInitialization();
|
|
332
|
+
await client.waitForInitialization(5);
|
|
333
333
|
|
|
334
334
|
expect(client.variation('enable-foo', 1)).toEqual(true);
|
|
335
335
|
});
|
|
@@ -341,7 +341,7 @@ describe('LDClient', () => {
|
|
|
341
341
|
await withServers(async (baseConfig, pollServer) => {
|
|
342
342
|
pollServer.byDefault(respondJson(flags));
|
|
343
343
|
await withClient(user, baseConfig, async client => {
|
|
344
|
-
await client.waitForInitialization();
|
|
344
|
+
await client.waitForInitialization(5);
|
|
345
345
|
|
|
346
346
|
expect(client.variation('foo', 'default')).toEqual('default');
|
|
347
347
|
});
|
|
@@ -352,7 +352,7 @@ describe('LDClient', () => {
|
|
|
352
352
|
await withServers(async (baseConfig, pollServer) => {
|
|
353
353
|
pollServer.byDefault(respondJson({}));
|
|
354
354
|
await withClient(user, baseConfig, async client => {
|
|
355
|
-
await client.waitForInitialization();
|
|
355
|
+
await client.waitForInitialization(5);
|
|
356
356
|
|
|
357
357
|
expect(client.variation('foo', 'default')).toEqual('default');
|
|
358
358
|
});
|
|
@@ -367,7 +367,7 @@ describe('LDClient', () => {
|
|
|
367
367
|
bootstrap: makeBootstrap({ foo: { value: 'bar', version: 1, variation: 2, reason: reason } }),
|
|
368
368
|
};
|
|
369
369
|
await withClient(user, config, async client => {
|
|
370
|
-
await client.waitForInitialization();
|
|
370
|
+
await client.waitForInitialization(5);
|
|
371
371
|
|
|
372
372
|
expect(client.variationDetail('foo')).toEqual({ value: 'bar', variationIndex: 2, reason: reason });
|
|
373
373
|
});
|
|
@@ -376,7 +376,7 @@ describe('LDClient', () => {
|
|
|
376
376
|
it('returns details for an existing flag - from bootstrap with old format', async () => {
|
|
377
377
|
const config = { bootstrap: { foo: 'bar' } };
|
|
378
378
|
await withClient(user, config, async client => {
|
|
379
|
-
await client.waitForInitialization();
|
|
379
|
+
await client.waitForInitialization(5);
|
|
380
380
|
|
|
381
381
|
expect(client.variationDetail('foo')).toEqual({ value: 'bar', variationIndex: null, reason: null });
|
|
382
382
|
});
|
|
@@ -387,7 +387,7 @@ describe('LDClient', () => {
|
|
|
387
387
|
await withServers(async (baseConfig, pollServer) => {
|
|
388
388
|
pollServer.byDefault(respondJson(flags));
|
|
389
389
|
await withClient(user, baseConfig, async client => {
|
|
390
|
-
await client.waitForInitialization();
|
|
390
|
+
await client.waitForInitialization(5);
|
|
391
391
|
|
|
392
392
|
expect(client.variationDetail('foo', 'default')).toEqual({ value: 'bar', variationIndex: 2, reason: reason });
|
|
393
393
|
});
|
|
@@ -399,7 +399,7 @@ describe('LDClient', () => {
|
|
|
399
399
|
await withServers(async (baseConfig, pollServer) => {
|
|
400
400
|
pollServer.byDefault(respondJson(flags));
|
|
401
401
|
await withClient(user, baseConfig, async client => {
|
|
402
|
-
await client.waitForInitialization();
|
|
402
|
+
await client.waitForInitialization(5);
|
|
403
403
|
|
|
404
404
|
expect(client.variationDetail('foo', 'default')).toEqual({
|
|
405
405
|
value: 'default',
|
|
@@ -430,7 +430,7 @@ describe('LDClient', () => {
|
|
|
430
430
|
await withServers(async (baseConfig, pollServer) => {
|
|
431
431
|
pollServer.byDefault(respondJson(flags));
|
|
432
432
|
await withClient(user, baseConfig, async client => {
|
|
433
|
-
await client.waitForInitialization();
|
|
433
|
+
await client.waitForInitialization(5);
|
|
434
434
|
|
|
435
435
|
expect(client.allFlags()).toEqual({ key1: 'value1', key2: 'value2' });
|
|
436
436
|
});
|
|
@@ -455,7 +455,7 @@ describe('LDClient', () => {
|
|
|
455
455
|
await withClient(user, baseConfig, async client => {
|
|
456
456
|
const signal = new AsyncQueue();
|
|
457
457
|
const user2 = { key: 'user2' };
|
|
458
|
-
await client.waitForInitialization();
|
|
458
|
+
await client.waitForInitialization(5);
|
|
459
459
|
|
|
460
460
|
// Make the server wait until signaled to return the next response
|
|
461
461
|
pollServer.byDefault((req, res) => {
|
|
@@ -483,7 +483,7 @@ describe('LDClient', () => {
|
|
|
483
483
|
await withServers(async (baseConfig, pollServer) => {
|
|
484
484
|
pollServer.byDefault(respondJson(flags0));
|
|
485
485
|
await withClient(user, baseConfig, async client => {
|
|
486
|
-
await client.waitForInitialization();
|
|
486
|
+
await client.waitForInitialization(5);
|
|
487
487
|
|
|
488
488
|
expect(client.variation('enable-foo')).toBe(false);
|
|
489
489
|
|
|
@@ -508,7 +508,7 @@ describe('LDClient', () => {
|
|
|
508
508
|
await withServers(async (baseConfig, pollServer) => {
|
|
509
509
|
pollServer.byDefault(respondJson(flags0));
|
|
510
510
|
await withClient(user, baseConfig, async client => {
|
|
511
|
-
await client.waitForInitialization();
|
|
511
|
+
await client.waitForInitialization(5);
|
|
512
512
|
|
|
513
513
|
expect(client.variation('enable-foo')).toBe(false);
|
|
514
514
|
expect(pollServer.requests.length()).toEqual(1);
|
|
@@ -531,7 +531,7 @@ describe('LDClient', () => {
|
|
|
531
531
|
it('provides a persistent key for an anonymous user with no key', async () => {
|
|
532
532
|
await withServers(async baseConfig => {
|
|
533
533
|
await withClient(user, baseConfig, async client => {
|
|
534
|
-
await client.waitForInitialization();
|
|
534
|
+
await client.waitForInitialization(5);
|
|
535
535
|
|
|
536
536
|
const anonUser = { anonymous: true, country: 'US' };
|
|
537
537
|
await client.identify(anonUser);
|
|
@@ -556,7 +556,7 @@ describe('LDClient', () => {
|
|
|
556
556
|
|
|
557
557
|
await withServers(async (baseConfig, pollServer) => {
|
|
558
558
|
await withClient(null, { ...baseConfig, stateProvider: sp }, async client => {
|
|
559
|
-
await client.waitForInitialization();
|
|
559
|
+
await client.waitForInitialization(5);
|
|
560
560
|
|
|
561
561
|
expect(client.variation('flagkey')).toEqual('value');
|
|
562
562
|
expect(pollServer.requests.length()).toEqual(0);
|
|
@@ -586,7 +586,7 @@ describe('LDClient', () => {
|
|
|
586
586
|
await withClient(null, { stateProvider: sp, sendEvents: false }, async client => {
|
|
587
587
|
sp.emit('init', state);
|
|
588
588
|
|
|
589
|
-
await client.waitForInitialization();
|
|
589
|
+
await client.waitForInitialization(5);
|
|
590
590
|
expect(client.variation('flagkey')).toEqual('value');
|
|
591
591
|
});
|
|
592
592
|
});
|
|
@@ -601,7 +601,7 @@ describe('LDClient', () => {
|
|
|
601
601
|
const sp = stubPlatform.mockStateProvider(state0);
|
|
602
602
|
|
|
603
603
|
await withClient(null, { stateProvider: sp, sendEvents: false }, async client => {
|
|
604
|
-
await client.waitForInitialization();
|
|
604
|
+
await client.waitForInitialization(5);
|
|
605
605
|
|
|
606
606
|
expect(client.variation('flagkey')).toEqual('value0');
|
|
607
607
|
|
|
@@ -628,7 +628,7 @@ describe('LDClient', () => {
|
|
|
628
628
|
await withClient(null, { ...baseConfig, stateProvider: sp }, async client => {
|
|
629
629
|
sp.emit('init', state);
|
|
630
630
|
|
|
631
|
-
await client.waitForInitialization();
|
|
631
|
+
await client.waitForInitialization(5);
|
|
632
632
|
const newFlags = await client.identify(user1);
|
|
633
633
|
|
|
634
634
|
expect(newFlags).toEqual({ flagkey: 'value' });
|
|
@@ -650,7 +650,7 @@ describe('LDClient', () => {
|
|
|
650
650
|
await withClient(null, { stateProvider: sp, sendEvents: false }, async client => {
|
|
651
651
|
sp.emit('init', state);
|
|
652
652
|
|
|
653
|
-
await client.waitForInitialization();
|
|
653
|
+
await client.waitForInitialization(5);
|
|
654
654
|
expect(client.variation('flagkey')).toEqual('value');
|
|
655
655
|
|
|
656
656
|
state.flags.flagkey = { value: 'secondValue' };
|
|
@@ -669,7 +669,7 @@ describe('LDClient', () => {
|
|
|
669
669
|
it('flushes events', async () => {
|
|
670
670
|
await withServers(async (baseConfig, pollServer, eventsServer) => {
|
|
671
671
|
await withClient(user, { ...baseConfig, flushInterval: 100000 }, async client => {
|
|
672
|
-
await client.waitForInitialization();
|
|
672
|
+
await client.waitForInitialization(5);
|
|
673
673
|
});
|
|
674
674
|
|
|
675
675
|
expect(eventsServer.requests.length()).toEqual(1);
|
|
@@ -683,7 +683,7 @@ describe('LDClient', () => {
|
|
|
683
683
|
it('does nothing if called twice', async () => {
|
|
684
684
|
await withServers(async (baseConfig, pollServer, eventsServer) => {
|
|
685
685
|
await withClient(user, { ...baseConfig, flushInterval: 100000 }, async client => {
|
|
686
|
-
await client.waitForInitialization();
|
|
686
|
+
await client.waitForInitialization(5);
|
|
687
687
|
|
|
688
688
|
await client.close();
|
|
689
689
|
|
|
@@ -700,7 +700,7 @@ describe('LDClient', () => {
|
|
|
700
700
|
await withServers(async (baseConfig, pollServer, eventsServer) => {
|
|
701
701
|
eventsServer.byDefault(respond(404));
|
|
702
702
|
await withClient(user, { ...baseConfig, flushInterval: 100000 }, async client => {
|
|
703
|
-
await client.waitForInitialization();
|
|
703
|
+
await client.waitForInitialization(5);
|
|
704
704
|
|
|
705
705
|
await client.close(); // shouldn't throw or have an unhandled rejection
|
|
706
706
|
});
|
|
@@ -710,7 +710,7 @@ describe('LDClient', () => {
|
|
|
710
710
|
it('can take a callback instead of returning a promise', async () => {
|
|
711
711
|
await withServers(async (baseConfig, pollServer, eventsServer) => {
|
|
712
712
|
await withClient(user, { ...baseConfig }, async client => {
|
|
713
|
-
await client.waitForInitialization();
|
|
713
|
+
await client.waitForInitialization(5);
|
|
714
714
|
|
|
715
715
|
await promisifySingle(client.close)();
|
|
716
716
|
|
|
@@ -730,7 +730,7 @@ describe('LDClient', () => {
|
|
|
730
730
|
it('sends diagnostic init event if not opted out', async () => {
|
|
731
731
|
await withServers(async (baseConfig, pollServer, eventsServer) => {
|
|
732
732
|
await withDiagnosticsEnabledClient(user, baseConfig, async client => {
|
|
733
|
-
await client.waitForInitialization();
|
|
733
|
+
await client.waitForInitialization(5);
|
|
734
734
|
await client.flush();
|
|
735
735
|
|
|
736
736
|
// We can't be sure which will be posted first, the regular events or the diagnostic event
|