@replanejs/test-suite 0.8.19 → 0.9.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/dist/index.cjs +109 -174
- package/dist/index.d.cts +4 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +110 -175
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -232,15 +232,17 @@ function createTestContext(admin, workspaceId, projectId, environmentId, sdkKey,
|
|
|
232
232
|
sync,
|
|
233
233
|
async createClient(clientOptions) {
|
|
234
234
|
await sync();
|
|
235
|
-
|
|
235
|
+
const client = new __replanejs_sdk.Replane({
|
|
236
|
+
logger: options.debug ? console : silentLogger,
|
|
237
|
+
context: clientOptions?.context,
|
|
238
|
+
defaults: clientOptions?.defaults
|
|
239
|
+
});
|
|
240
|
+
await client.connect({
|
|
236
241
|
sdkKey,
|
|
237
242
|
baseUrl: options.edgeApiBaseUrl,
|
|
238
|
-
|
|
239
|
-
initializationTimeoutMs: defaultTimeout,
|
|
240
|
-
context: clientOptions?.context,
|
|
241
|
-
defaults: clientOptions?.defaults,
|
|
242
|
-
required: clientOptions?.required
|
|
243
|
+
connectTimeoutMs: defaultTimeout
|
|
243
244
|
});
|
|
245
|
+
return client;
|
|
244
246
|
},
|
|
245
247
|
async createConfig(name, value, configOptions) {
|
|
246
248
|
await admin.configs.create({
|
|
@@ -248,7 +250,6 @@ function createTestContext(admin, workspaceId, projectId, environmentId, sdkKey,
|
|
|
248
250
|
name,
|
|
249
251
|
description: configOptions?.description ?? "",
|
|
250
252
|
editors: [],
|
|
251
|
-
maintainers: [],
|
|
252
253
|
base: {
|
|
253
254
|
value,
|
|
254
255
|
schema: null,
|
|
@@ -340,7 +341,7 @@ function testSuite(options) {
|
|
|
340
341
|
});
|
|
341
342
|
(0, vitest.afterAll)(async () => {
|
|
342
343
|
for (const client of activeClients) try {
|
|
343
|
-
client.
|
|
344
|
+
client.disconnect();
|
|
344
345
|
} catch {}
|
|
345
346
|
activeClients.length = 0;
|
|
346
347
|
if (workspaceId) await admin.workspaces.delete({ workspaceId });
|
|
@@ -363,10 +364,10 @@ function testSuite(options) {
|
|
|
363
364
|
(0, vitest.describe)("SDK Connection", () => {
|
|
364
365
|
(0, vitest.it)("should connect and receive initial configs", async () => {
|
|
365
366
|
await ctx.createConfig("test-config", "initial-value");
|
|
366
|
-
const client = trackClient(await ctx.createClient({
|
|
367
|
+
const client = trackClient(await ctx.createClient({}));
|
|
367
368
|
const value = client.get("test-config");
|
|
368
369
|
(0, vitest.expect)(value).toBe("initial-value");
|
|
369
|
-
client.
|
|
370
|
+
client.disconnect();
|
|
370
371
|
});
|
|
371
372
|
(0, vitest.it)("should handle empty project (no configs)", async () => {
|
|
372
373
|
const emptyProjectRes = await admin.projects.create({
|
|
@@ -385,51 +386,49 @@ function testSuite(options) {
|
|
|
385
386
|
edgeApiBaseUrl,
|
|
386
387
|
sdkKey
|
|
387
388
|
});
|
|
388
|
-
const
|
|
389
|
+
const emptyClient = new __replanejs_sdk.Replane({ logger: silentLogger });
|
|
390
|
+
await emptyClient.connect({
|
|
389
391
|
sdkKey: emptySdkKeyRes.key,
|
|
390
392
|
baseUrl: edgeApiBaseUrl,
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
393
|
+
connectTimeoutMs: defaultTimeout
|
|
394
|
+
});
|
|
395
|
+
const client = trackClient(emptyClient);
|
|
394
396
|
(0, vitest.expect)(() => client.get("nonexistent")).toThrow();
|
|
395
|
-
client.
|
|
397
|
+
client.disconnect();
|
|
396
398
|
await admin.projects.delete({ projectId: emptyProjectRes.id });
|
|
397
399
|
});
|
|
398
400
|
(0, vitest.it)("should use default values when config not found", async () => {
|
|
399
401
|
const client = trackClient(await ctx.createClient({ defaults: { "missing-config": "default-value" } }));
|
|
400
402
|
const value = client.get("missing-config");
|
|
401
403
|
(0, vitest.expect)(value).toBe("default-value");
|
|
402
|
-
client.
|
|
403
|
-
});
|
|
404
|
-
(0, vitest.it)("should throw when required config is missing", { timeout: 15e3 }, async () => {
|
|
405
|
-
await (0, vitest.expect)(ctx.createClient({ required: ["definitely-missing-config"] })).rejects.toThrow();
|
|
404
|
+
client.disconnect();
|
|
406
405
|
});
|
|
407
406
|
});
|
|
408
407
|
(0, vitest.describe)("Get Config", () => {
|
|
409
408
|
(0, vitest.it)("should get string config", async () => {
|
|
410
409
|
await ctx.createConfig("string-config", "hello");
|
|
411
|
-
const client = trackClient(await ctx.createClient({
|
|
410
|
+
const client = trackClient(await ctx.createClient({}));
|
|
412
411
|
(0, vitest.expect)(client.get("string-config")).toBe("hello");
|
|
413
|
-
client.
|
|
412
|
+
client.disconnect();
|
|
414
413
|
});
|
|
415
414
|
(0, vitest.it)("should get number config", async () => {
|
|
416
415
|
await ctx.createConfig("number-config", 42);
|
|
417
|
-
const client = trackClient(await ctx.createClient({
|
|
416
|
+
const client = trackClient(await ctx.createClient({}));
|
|
418
417
|
(0, vitest.expect)(client.get("number-config")).toBe(42);
|
|
419
|
-
client.
|
|
418
|
+
client.disconnect();
|
|
420
419
|
});
|
|
421
420
|
(0, vitest.it)("should get boolean config", async () => {
|
|
422
421
|
await ctx.createConfig("boolean-config", true);
|
|
423
|
-
const client = trackClient(await ctx.createClient({
|
|
422
|
+
const client = trackClient(await ctx.createClient({}));
|
|
424
423
|
(0, vitest.expect)(client.get("boolean-config")).toBe(true);
|
|
425
|
-
client.
|
|
424
|
+
client.disconnect();
|
|
426
425
|
});
|
|
427
426
|
(0, vitest.it)("should get object config", async () => {
|
|
428
427
|
const objValue = { nested: { value: "deep" } };
|
|
429
428
|
await ctx.createConfig("object-config", objValue);
|
|
430
|
-
const client = trackClient(await ctx.createClient({
|
|
429
|
+
const client = trackClient(await ctx.createClient({}));
|
|
431
430
|
(0, vitest.expect)(client.get("object-config")).toEqual(objValue);
|
|
432
|
-
client.
|
|
431
|
+
client.disconnect();
|
|
433
432
|
});
|
|
434
433
|
(0, vitest.it)("should get array config", async () => {
|
|
435
434
|
const arrValue = [
|
|
@@ -438,21 +437,21 @@ function testSuite(options) {
|
|
|
438
437
|
3
|
|
439
438
|
];
|
|
440
439
|
await ctx.createConfig("array-config", arrValue);
|
|
441
|
-
const client = trackClient(await ctx.createClient({
|
|
440
|
+
const client = trackClient(await ctx.createClient({}));
|
|
442
441
|
(0, vitest.expect)(client.get("array-config")).toEqual(arrValue);
|
|
443
|
-
client.
|
|
442
|
+
client.disconnect();
|
|
444
443
|
});
|
|
445
444
|
(0, vitest.it)("should get null config", async () => {
|
|
446
445
|
await ctx.createConfig("null-config", null);
|
|
447
|
-
const client = trackClient(await ctx.createClient({
|
|
446
|
+
const client = trackClient(await ctx.createClient({}));
|
|
448
447
|
(0, vitest.expect)(client.get("null-config")).toBe(null);
|
|
449
|
-
client.
|
|
448
|
+
client.disconnect();
|
|
450
449
|
});
|
|
451
450
|
(0, vitest.it)("should return default value when config not found", async () => {
|
|
452
451
|
const client = trackClient(await ctx.createClient());
|
|
453
452
|
const value = client.get("nonexistent", { default: "fallback" });
|
|
454
453
|
(0, vitest.expect)(value).toBe("fallback");
|
|
455
|
-
client.
|
|
454
|
+
client.disconnect();
|
|
456
455
|
});
|
|
457
456
|
(0, vitest.it)("should throw ReplaneError when config not found and no default", async () => {
|
|
458
457
|
const client = trackClient(await ctx.createClient());
|
|
@@ -463,13 +462,13 @@ function testSuite(options) {
|
|
|
463
462
|
(0, vitest.expect)(error).toBeInstanceOf(__replanejs_sdk.ReplaneError);
|
|
464
463
|
(0, vitest.expect)(error.code).toBe(__replanejs_sdk.ReplaneErrorCode.NotFound);
|
|
465
464
|
}
|
|
466
|
-
client.
|
|
465
|
+
client.disconnect();
|
|
467
466
|
});
|
|
468
467
|
});
|
|
469
468
|
(0, vitest.describe)("Real-time Updates", () => {
|
|
470
469
|
(0, vitest.it)("should receive config updates via subscription", async () => {
|
|
471
470
|
await ctx.createConfig("live-config", "initial");
|
|
472
|
-
const client = trackClient(await ctx.createClient({
|
|
471
|
+
const client = trackClient(await ctx.createClient({}));
|
|
473
472
|
(0, vitest.expect)(client.get("live-config")).toBe("initial");
|
|
474
473
|
const updateSignal = createSignal();
|
|
475
474
|
client.subscribe("live-config", (config) => {
|
|
@@ -479,11 +478,11 @@ function testSuite(options) {
|
|
|
479
478
|
const newValue = await updateSignal.wait({ timeout: defaultTimeout });
|
|
480
479
|
(0, vitest.expect)(newValue).toBe("updated");
|
|
481
480
|
(0, vitest.expect)(client.get("live-config")).toBe("updated");
|
|
482
|
-
client.
|
|
481
|
+
client.disconnect();
|
|
483
482
|
});
|
|
484
483
|
(0, vitest.it)("should receive multiple updates in order", async () => {
|
|
485
484
|
await ctx.createConfig("multi-update-config", 0);
|
|
486
|
-
const client = trackClient(await ctx.createClient({
|
|
485
|
+
const client = trackClient(await ctx.createClient({}));
|
|
487
486
|
(0, vitest.expect)(client.get("multi-update-config")).toBe(0);
|
|
488
487
|
const collector = createCollector();
|
|
489
488
|
client.subscribe("multi-update-config", (config) => {
|
|
@@ -501,11 +500,11 @@ function testSuite(options) {
|
|
|
501
500
|
2,
|
|
502
501
|
3
|
|
503
502
|
]);
|
|
504
|
-
client.
|
|
503
|
+
client.disconnect();
|
|
505
504
|
});
|
|
506
505
|
(0, vitest.it)("should handle rapid updates", async () => {
|
|
507
506
|
await ctx.createConfig("rapid-config", 0);
|
|
508
|
-
const client = trackClient(await ctx.createClient({
|
|
507
|
+
const client = trackClient(await ctx.createClient({}));
|
|
509
508
|
(0, vitest.expect)(client.get("rapid-config")).toBe(0);
|
|
510
509
|
const collector = createCollector();
|
|
511
510
|
client.subscribe("rapid-config", (config) => {
|
|
@@ -515,12 +514,12 @@ function testSuite(options) {
|
|
|
515
514
|
for (let i = 1; i <= updateCount; i++) await ctx.updateConfig("rapid-config", i);
|
|
516
515
|
await collector.waitFor((v) => v === updateCount, { timeout: defaultTimeout });
|
|
517
516
|
(0, vitest.expect)(client.get("rapid-config")).toBe(updateCount);
|
|
518
|
-
client.
|
|
517
|
+
client.disconnect();
|
|
519
518
|
});
|
|
520
519
|
(0, vitest.it)("should call global subscription for any config change", async () => {
|
|
521
520
|
await ctx.createConfig("config-a", "a");
|
|
522
521
|
await ctx.createConfig("config-b", "b");
|
|
523
|
-
const client = trackClient(await ctx.createClient({
|
|
522
|
+
const client = trackClient(await ctx.createClient({}));
|
|
524
523
|
(0, vitest.expect)(client.get("config-a")).toBe("a");
|
|
525
524
|
(0, vitest.expect)(client.get("config-b")).toBe("b");
|
|
526
525
|
const collector = createCollector();
|
|
@@ -538,11 +537,11 @@ function testSuite(options) {
|
|
|
538
537
|
const bUpdate = values.find((v) => v.name === "config-b");
|
|
539
538
|
(0, vitest.expect)(aUpdate?.value).toBe("a-updated");
|
|
540
539
|
(0, vitest.expect)(bUpdate?.value).toBe("b-updated");
|
|
541
|
-
client.
|
|
540
|
+
client.disconnect();
|
|
542
541
|
});
|
|
543
542
|
(0, vitest.it)("should allow unsubscribing", async () => {
|
|
544
543
|
await ctx.createConfig("unsub-config", "initial");
|
|
545
|
-
const client = trackClient(await ctx.createClient({
|
|
544
|
+
const client = trackClient(await ctx.createClient({}));
|
|
546
545
|
(0, vitest.expect)(client.get("unsub-config")).toBe("initial");
|
|
547
546
|
const collector = createCollector();
|
|
548
547
|
const unsubscribe = client.subscribe("unsub-config", (config) => {
|
|
@@ -554,7 +553,7 @@ function testSuite(options) {
|
|
|
554
553
|
await ctx.updateConfig("unsub-config", "update-2");
|
|
555
554
|
await delay(2e3);
|
|
556
555
|
(0, vitest.expect)(collector.count()).toBe(1);
|
|
557
|
-
client.
|
|
556
|
+
client.disconnect();
|
|
558
557
|
});
|
|
559
558
|
});
|
|
560
559
|
(0, vitest.describe)("Override Evaluation", () => {
|
|
@@ -568,21 +567,15 @@ function testSuite(options) {
|
|
|
568
567
|
}],
|
|
569
568
|
value: "production-value"
|
|
570
569
|
}] });
|
|
571
|
-
const client1 = trackClient(await ctx.createClient({
|
|
570
|
+
const client1 = trackClient(await ctx.createClient({}));
|
|
572
571
|
(0, vitest.expect)(client1.get("env-config")).toBe("default");
|
|
573
|
-
client1.
|
|
574
|
-
const client2 = trackClient(await ctx.createClient({
|
|
575
|
-
context: { env: "production" },
|
|
576
|
-
required: ["env-config"]
|
|
577
|
-
}));
|
|
572
|
+
client1.disconnect();
|
|
573
|
+
const client2 = trackClient(await ctx.createClient({ context: { env: "production" } }));
|
|
578
574
|
(0, vitest.expect)(client2.get("env-config")).toBe("production-value");
|
|
579
|
-
client2.
|
|
580
|
-
const client3 = trackClient(await ctx.createClient({
|
|
581
|
-
context: { env: "staging" },
|
|
582
|
-
required: ["env-config"]
|
|
583
|
-
}));
|
|
575
|
+
client2.disconnect();
|
|
576
|
+
const client3 = trackClient(await ctx.createClient({ context: { env: "staging" } }));
|
|
584
577
|
(0, vitest.expect)(client3.get("env-config")).toBe("default");
|
|
585
|
-
client3.
|
|
578
|
+
client3.disconnect();
|
|
586
579
|
});
|
|
587
580
|
(0, vitest.it)("should evaluate in condition", async () => {
|
|
588
581
|
await ctx.createConfig("region-config", "default", { overrides: [{
|
|
@@ -594,24 +587,15 @@ function testSuite(options) {
|
|
|
594
587
|
}],
|
|
595
588
|
value: "western"
|
|
596
589
|
}] });
|
|
597
|
-
const client1 = trackClient(await ctx.createClient({
|
|
598
|
-
context: { region: "us" },
|
|
599
|
-
required: ["region-config"]
|
|
600
|
-
}));
|
|
590
|
+
const client1 = trackClient(await ctx.createClient({ context: { region: "us" } }));
|
|
601
591
|
(0, vitest.expect)(client1.get("region-config")).toBe("western");
|
|
602
|
-
client1.
|
|
603
|
-
const client2 = trackClient(await ctx.createClient({
|
|
604
|
-
context: { region: "eu" },
|
|
605
|
-
required: ["region-config"]
|
|
606
|
-
}));
|
|
592
|
+
client1.disconnect();
|
|
593
|
+
const client2 = trackClient(await ctx.createClient({ context: { region: "eu" } }));
|
|
607
594
|
(0, vitest.expect)(client2.get("region-config")).toBe("western");
|
|
608
|
-
client2.
|
|
609
|
-
const client3 = trackClient(await ctx.createClient({
|
|
610
|
-
context: { region: "asia" },
|
|
611
|
-
required: ["region-config"]
|
|
612
|
-
}));
|
|
595
|
+
client2.disconnect();
|
|
596
|
+
const client3 = trackClient(await ctx.createClient({ context: { region: "asia" } }));
|
|
613
597
|
(0, vitest.expect)(client3.get("region-config")).toBe("default");
|
|
614
|
-
client3.
|
|
598
|
+
client3.disconnect();
|
|
615
599
|
});
|
|
616
600
|
(0, vitest.it)("should evaluate not_in condition", async () => {
|
|
617
601
|
await ctx.createConfig("allow-config", "allowed", { overrides: [{
|
|
@@ -623,18 +607,12 @@ function testSuite(options) {
|
|
|
623
607
|
}],
|
|
624
608
|
value: "not-blocked"
|
|
625
609
|
}] });
|
|
626
|
-
const client1 = trackClient(await ctx.createClient({
|
|
627
|
-
context: { country: "blocked1" },
|
|
628
|
-
required: ["allow-config"]
|
|
629
|
-
}));
|
|
610
|
+
const client1 = trackClient(await ctx.createClient({ context: { country: "blocked1" } }));
|
|
630
611
|
(0, vitest.expect)(client1.get("allow-config")).toBe("allowed");
|
|
631
|
-
client1.
|
|
632
|
-
const client2 = trackClient(await ctx.createClient({
|
|
633
|
-
context: { country: "normal" },
|
|
634
|
-
required: ["allow-config"]
|
|
635
|
-
}));
|
|
612
|
+
client1.disconnect();
|
|
613
|
+
const client2 = trackClient(await ctx.createClient({ context: { country: "normal" } }));
|
|
636
614
|
(0, vitest.expect)(client2.get("allow-config")).toBe("not-blocked");
|
|
637
|
-
client2.
|
|
615
|
+
client2.disconnect();
|
|
638
616
|
});
|
|
639
617
|
(0, vitest.it)("should evaluate numeric comparison conditions", async () => {
|
|
640
618
|
await ctx.createConfig("tier-config", "free", { overrides: [{
|
|
@@ -646,24 +624,15 @@ function testSuite(options) {
|
|
|
646
624
|
}],
|
|
647
625
|
value: "premium"
|
|
648
626
|
}] });
|
|
649
|
-
const client1 = trackClient(await ctx.createClient({
|
|
650
|
-
context: { level: 5 },
|
|
651
|
-
required: ["tier-config"]
|
|
652
|
-
}));
|
|
627
|
+
const client1 = trackClient(await ctx.createClient({ context: { level: 5 } }));
|
|
653
628
|
(0, vitest.expect)(client1.get("tier-config")).toBe("free");
|
|
654
|
-
client1.
|
|
655
|
-
const client2 = trackClient(await ctx.createClient({
|
|
656
|
-
context: { level: 10 },
|
|
657
|
-
required: ["tier-config"]
|
|
658
|
-
}));
|
|
629
|
+
client1.disconnect();
|
|
630
|
+
const client2 = trackClient(await ctx.createClient({ context: { level: 10 } }));
|
|
659
631
|
(0, vitest.expect)(client2.get("tier-config")).toBe("premium");
|
|
660
|
-
client2.
|
|
661
|
-
const client3 = trackClient(await ctx.createClient({
|
|
662
|
-
context: { level: 15 },
|
|
663
|
-
required: ["tier-config"]
|
|
664
|
-
}));
|
|
632
|
+
client2.disconnect();
|
|
633
|
+
const client3 = trackClient(await ctx.createClient({ context: { level: 15 } }));
|
|
665
634
|
(0, vitest.expect)(client3.get("tier-config")).toBe("premium");
|
|
666
|
-
client3.
|
|
635
|
+
client3.disconnect();
|
|
667
636
|
});
|
|
668
637
|
(0, vitest.it)("should evaluate and condition", async () => {
|
|
669
638
|
await ctx.createConfig("combo-config", "default", { overrides: [{
|
|
@@ -682,24 +651,18 @@ function testSuite(options) {
|
|
|
682
651
|
}],
|
|
683
652
|
value: "enterprise-verified"
|
|
684
653
|
}] });
|
|
685
|
-
const client1 = trackClient(await ctx.createClient({
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
},
|
|
690
|
-
required: ["combo-config"]
|
|
691
|
-
}));
|
|
654
|
+
const client1 = trackClient(await ctx.createClient({ context: {
|
|
655
|
+
plan: "enterprise",
|
|
656
|
+
verified: true
|
|
657
|
+
} }));
|
|
692
658
|
(0, vitest.expect)(client1.get("combo-config")).toBe("enterprise-verified");
|
|
693
|
-
client1.
|
|
694
|
-
const client2 = trackClient(await ctx.createClient({
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
},
|
|
699
|
-
required: ["combo-config"]
|
|
700
|
-
}));
|
|
659
|
+
client1.disconnect();
|
|
660
|
+
const client2 = trackClient(await ctx.createClient({ context: {
|
|
661
|
+
plan: "enterprise",
|
|
662
|
+
verified: false
|
|
663
|
+
} }));
|
|
701
664
|
(0, vitest.expect)(client2.get("combo-config")).toBe("default");
|
|
702
|
-
client2.
|
|
665
|
+
client2.disconnect();
|
|
703
666
|
});
|
|
704
667
|
(0, vitest.it)("should evaluate or condition", async () => {
|
|
705
668
|
await ctx.createConfig("either-config", "default", { overrides: [{
|
|
@@ -718,24 +681,15 @@ function testSuite(options) {
|
|
|
718
681
|
}],
|
|
719
682
|
value: "privileged"
|
|
720
683
|
}] });
|
|
721
|
-
const client1 = trackClient(await ctx.createClient({
|
|
722
|
-
context: { role: "admin" },
|
|
723
|
-
required: ["either-config"]
|
|
724
|
-
}));
|
|
684
|
+
const client1 = trackClient(await ctx.createClient({ context: { role: "admin" } }));
|
|
725
685
|
(0, vitest.expect)(client1.get("either-config")).toBe("privileged");
|
|
726
|
-
client1.
|
|
727
|
-
const client2 = trackClient(await ctx.createClient({
|
|
728
|
-
context: { role: "superadmin" },
|
|
729
|
-
required: ["either-config"]
|
|
730
|
-
}));
|
|
686
|
+
client1.disconnect();
|
|
687
|
+
const client2 = trackClient(await ctx.createClient({ context: { role: "superadmin" } }));
|
|
731
688
|
(0, vitest.expect)(client2.get("either-config")).toBe("privileged");
|
|
732
|
-
client2.
|
|
733
|
-
const client3 = trackClient(await ctx.createClient({
|
|
734
|
-
context: { role: "user" },
|
|
735
|
-
required: ["either-config"]
|
|
736
|
-
}));
|
|
689
|
+
client2.disconnect();
|
|
690
|
+
const client3 = trackClient(await ctx.createClient({ context: { role: "user" } }));
|
|
737
691
|
(0, vitest.expect)(client3.get("either-config")).toBe("default");
|
|
738
|
-
client3.
|
|
692
|
+
client3.disconnect();
|
|
739
693
|
});
|
|
740
694
|
(0, vitest.it)("should allow per-request context override", async () => {
|
|
741
695
|
await ctx.createConfig("dynamic-config", "default", { overrides: [{
|
|
@@ -747,11 +701,11 @@ function testSuite(options) {
|
|
|
747
701
|
}],
|
|
748
702
|
value: "feature-on"
|
|
749
703
|
}] });
|
|
750
|
-
const client = trackClient(await ctx.createClient({
|
|
704
|
+
const client = trackClient(await ctx.createClient({}));
|
|
751
705
|
(0, vitest.expect)(client.get("dynamic-config")).toBe("default");
|
|
752
706
|
(0, vitest.expect)(client.get("dynamic-config", { context: { feature: "enabled" } })).toBe("feature-on");
|
|
753
707
|
(0, vitest.expect)(client.get("dynamic-config")).toBe("default");
|
|
754
|
-
client.
|
|
708
|
+
client.disconnect();
|
|
755
709
|
});
|
|
756
710
|
(0, vitest.it)("should apply first matching override", async () => {
|
|
757
711
|
await ctx.createConfig("priority-config", "default", { overrides: [
|
|
@@ -783,22 +737,19 @@ function testSuite(options) {
|
|
|
783
737
|
value: "has-score"
|
|
784
738
|
}
|
|
785
739
|
] });
|
|
786
|
-
const client = trackClient(await ctx.createClient({
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
},
|
|
791
|
-
required: ["priority-config"]
|
|
792
|
-
}));
|
|
740
|
+
const client = trackClient(await ctx.createClient({ context: {
|
|
741
|
+
tier: "gold",
|
|
742
|
+
score: 100
|
|
743
|
+
} }));
|
|
793
744
|
(0, vitest.expect)(client.get("priority-config")).toBe("gold-value");
|
|
794
|
-
client.
|
|
745
|
+
client.disconnect();
|
|
795
746
|
});
|
|
796
747
|
});
|
|
797
748
|
(0, vitest.describe)("Snapshot", () => {
|
|
798
749
|
(0, vitest.it)("should create snapshot with current configs", async () => {
|
|
799
750
|
await ctx.createConfig("snap-config-1", "value-1");
|
|
800
751
|
await ctx.createConfig("snap-config-2", "value-2");
|
|
801
|
-
const client = trackClient(await ctx.createClient({
|
|
752
|
+
const client = trackClient(await ctx.createClient({}));
|
|
802
753
|
const snapshot = client.getSnapshot();
|
|
803
754
|
(0, vitest.expect)(snapshot.configs).toMatchInlineSnapshot(`
|
|
804
755
|
[
|
|
@@ -815,42 +766,32 @@ function testSuite(options) {
|
|
|
815
766
|
]
|
|
816
767
|
`);
|
|
817
768
|
(0, vitest.expect)(snapshot.configs.map((c) => c.name).sort()).toEqual(["snap-config-1", "snap-config-2"]);
|
|
818
|
-
client.
|
|
819
|
-
});
|
|
820
|
-
(0, vitest.it)("should include context in snapshot", async () => {
|
|
821
|
-
await ctx.createConfig("ctx-config", "value");
|
|
822
|
-
const client = trackClient(await ctx.createClient({
|
|
823
|
-
context: { userId: "123" },
|
|
824
|
-
required: ["ctx-config"]
|
|
825
|
-
}));
|
|
826
|
-
const snapshot = client.getSnapshot();
|
|
827
|
-
(0, vitest.expect)(snapshot.context).toEqual({ userId: "123" });
|
|
828
|
-
client.close();
|
|
769
|
+
client.disconnect();
|
|
829
770
|
});
|
|
830
771
|
});
|
|
831
772
|
(0, vitest.describe)("Error Handling", () => {
|
|
832
773
|
(0, vitest.it)("should throw on invalid SDK key", async () => {
|
|
833
|
-
|
|
774
|
+
const invalidClient = new __replanejs_sdk.Replane({ logger: silentLogger });
|
|
775
|
+
await (0, vitest.expect)(invalidClient.connect({
|
|
834
776
|
sdkKey: "invalid-key",
|
|
835
777
|
baseUrl: edgeApiBaseUrl,
|
|
836
|
-
|
|
837
|
-
initializationTimeoutMs: 2e3
|
|
778
|
+
connectTimeoutMs: 2e3
|
|
838
779
|
})).rejects.toThrow();
|
|
839
780
|
});
|
|
840
|
-
(0, vitest.it)("should handle
|
|
781
|
+
(0, vitest.it)("should handle disconnected client gracefully", async () => {
|
|
841
782
|
await ctx.createConfig("close-test", "value");
|
|
842
|
-
const client = trackClient(await ctx.createClient({
|
|
783
|
+
const client = trackClient(await ctx.createClient({ defaults: { "close-test": "default" } }));
|
|
843
784
|
(0, vitest.expect)(client.get("close-test")).toBe("value");
|
|
844
|
-
client.
|
|
785
|
+
client.disconnect();
|
|
845
786
|
const cachedValue = client.get("close-test");
|
|
846
787
|
(0, vitest.expect)(cachedValue).toBe("value");
|
|
847
788
|
});
|
|
848
789
|
(0, vitest.it)("should timeout on unreachable server", async () => {
|
|
849
|
-
|
|
790
|
+
const unreachableClient = new __replanejs_sdk.Replane({ logger: silentLogger });
|
|
791
|
+
await (0, vitest.expect)(unreachableClient.connect({
|
|
850
792
|
sdkKey: "rp_test",
|
|
851
793
|
baseUrl: "http://localhost:59999",
|
|
852
|
-
|
|
853
|
-
initializationTimeoutMs: 1e3
|
|
794
|
+
connectTimeoutMs: 1e3
|
|
854
795
|
})).rejects.toThrow();
|
|
855
796
|
});
|
|
856
797
|
});
|
|
@@ -865,23 +806,23 @@ function testSuite(options) {
|
|
|
865
806
|
const value = await configSignal.wait({ timeout: defaultTimeout });
|
|
866
807
|
(0, vitest.expect)(value).toBe("late-value");
|
|
867
808
|
(0, vitest.expect)(client.get("late-config")).toBe("late-value");
|
|
868
|
-
client.
|
|
809
|
+
client.disconnect();
|
|
869
810
|
});
|
|
870
811
|
(0, vitest.it)("should ignore config deletion on client", async () => {
|
|
871
812
|
await ctx.createConfig("delete-me", "exists");
|
|
872
|
-
const client = trackClient(await ctx.createClient({
|
|
813
|
+
const client = trackClient(await ctx.createClient({}));
|
|
873
814
|
(0, vitest.expect)(client.get("delete-me")).toBe("exists");
|
|
874
815
|
await ctx.deleteConfig("delete-me");
|
|
875
816
|
await delay(1e3);
|
|
876
817
|
(0, vitest.expect)(client.get("delete-me")).toBe("exists");
|
|
877
|
-
client.
|
|
818
|
+
client.disconnect();
|
|
878
819
|
});
|
|
879
820
|
});
|
|
880
821
|
(0, vitest.describe)("Concurrent Clients", () => {
|
|
881
822
|
(0, vitest.it)("should handle multiple clients with same SDK key", async () => {
|
|
882
823
|
await ctx.createConfig("shared-config", "initial");
|
|
883
|
-
const client1 = trackClient(await ctx.createClient({
|
|
884
|
-
const client2 = trackClient(await ctx.createClient({
|
|
824
|
+
const client1 = trackClient(await ctx.createClient({}));
|
|
825
|
+
const client2 = trackClient(await ctx.createClient({}));
|
|
885
826
|
(0, vitest.expect)(client1.get("shared-config")).toBe("initial");
|
|
886
827
|
(0, vitest.expect)(client2.get("shared-config")).toBe("initial");
|
|
887
828
|
const signal1 = createSignal();
|
|
@@ -896,8 +837,8 @@ function testSuite(options) {
|
|
|
896
837
|
const [v1, v2] = await Promise.all([signal1.wait({ timeout: defaultTimeout }), signal2.wait({ timeout: defaultTimeout })]);
|
|
897
838
|
(0, vitest.expect)(v1).toBe("updated");
|
|
898
839
|
(0, vitest.expect)(v2).toBe("updated");
|
|
899
|
-
client1.
|
|
900
|
-
client2.
|
|
840
|
+
client1.disconnect();
|
|
841
|
+
client2.disconnect();
|
|
901
842
|
});
|
|
902
843
|
(0, vitest.it)("should isolate context between clients", async () => {
|
|
903
844
|
await ctx.createConfig("context-config", "default", { overrides: [{
|
|
@@ -909,18 +850,12 @@ function testSuite(options) {
|
|
|
909
850
|
}],
|
|
910
851
|
value: "prod-value"
|
|
911
852
|
}] });
|
|
912
|
-
const client1 = trackClient(await ctx.createClient({
|
|
913
|
-
|
|
914
|
-
required: ["context-config"]
|
|
915
|
-
}));
|
|
916
|
-
const client2 = trackClient(await ctx.createClient({
|
|
917
|
-
context: { env: "dev" },
|
|
918
|
-
required: ["context-config"]
|
|
919
|
-
}));
|
|
853
|
+
const client1 = trackClient(await ctx.createClient({ context: { env: "prod" } }));
|
|
854
|
+
const client2 = trackClient(await ctx.createClient({ context: { env: "dev" } }));
|
|
920
855
|
(0, vitest.expect)(client1.get("context-config")).toBe("prod-value");
|
|
921
856
|
(0, vitest.expect)(client2.get("context-config")).toBe("default");
|
|
922
|
-
client1.
|
|
923
|
-
client2.
|
|
857
|
+
client1.disconnect();
|
|
858
|
+
client2.disconnect();
|
|
924
859
|
});
|
|
925
860
|
});
|
|
926
861
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ConfigValue, Override, ReplaneAdmin } from "@replanejs/admin";
|
|
2
|
-
import {
|
|
2
|
+
import { Replane } from "@replanejs/sdk";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
5
|
|
|
@@ -15,6 +15,8 @@ interface TestSuiteOptions {
|
|
|
15
15
|
edgeApiBaseUrl: string;
|
|
16
16
|
/** Default timeout for waiting operations in ms (default: 5000) */
|
|
17
17
|
defaultTimeout?: number;
|
|
18
|
+
/** Enable debug logging */
|
|
19
|
+
debug?: boolean;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* Test context available in each test
|
|
@@ -46,8 +48,7 @@ interface TestContext {
|
|
|
46
48
|
createClient<T extends object = Record<string, unknown>>(options?: {
|
|
47
49
|
context?: Record<string, string | number | boolean | null | undefined>;
|
|
48
50
|
defaults?: Partial<T>;
|
|
49
|
-
|
|
50
|
-
}): Promise<ReplaneClient<T>>;
|
|
51
|
+
}): Promise<Replane<T>>;
|
|
51
52
|
/**
|
|
52
53
|
* Create a config in the test project
|
|
53
54
|
*/
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/test-suite.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;;AAMA;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/test-suite.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;;AAMA;AAgBiB,UAhBA,gBAAA,CAgBW;EAAA;EAAA,aAEnB,EAAA,MAAA;EAAY;EAmBJ,eAKiB,EAAA,MAAA;EAAM;EACpB,cACG,EAAA,MAAA;EAAC;EAAF,cACA,CAAA,EAAA,MAAA;EAAC;EAAF,KAAf,CAAA,EAAA,OAAA;;;;;AAsBY,UAnDD,WAAA,CAmDC;EAAQ;EAEd,KAKkB,EAxDrB,YAwDqB;EAAO;;;;ECoErB;;;;EChJC;EAAQ,cAAA,EAAA,MAAA;EAAA;EACL,eAAT,EAAA,MAAA;EAAO;EACE,cAAA,EAAA,MAAA;EAOJ;;;EAA+B,IAAV,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
2
|
+
import { Replane } from "@replanejs/sdk";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
5
|
|
|
@@ -15,6 +15,8 @@ interface TestSuiteOptions {
|
|
|
15
15
|
edgeApiBaseUrl: string;
|
|
16
16
|
/** Default timeout for waiting operations in ms (default: 5000) */
|
|
17
17
|
defaultTimeout?: number;
|
|
18
|
+
/** Enable debug logging */
|
|
19
|
+
debug?: boolean;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* Test context available in each test
|
|
@@ -46,8 +48,7 @@ interface TestContext {
|
|
|
46
48
|
createClient<T extends object = Record<string, unknown>>(options?: {
|
|
47
49
|
context?: Record<string, string | number | boolean | null | undefined>;
|
|
48
50
|
defaults?: Partial<T>;
|
|
49
|
-
|
|
50
|
-
}): Promise<ReplaneClient<T>>;
|
|
51
|
+
}): Promise<Replane<T>>;
|
|
51
52
|
/**
|
|
52
53
|
* Create a config in the test project
|
|
53
54
|
*/
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/test-suite.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;;AAMA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/test-suite.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;;AAMA;AAgBiB,UAhBA,gBAAA,CAgBW;EAAA;EAAA,aAEnB,EAAA,MAAA;EAAY;EAmBJ,eAKiB,EAAA,MAAA;EAAM;EACpB,cACG,EAAA,MAAA;EAAC;EAAF,cACA,CAAA,EAAA,MAAA;EAAC;EAAF,KAAf,CAAA,EAAA,OAAA;;;;;AAsBY,UAnDD,WAAA,CAmDC;EAAQ;EAEd,KAKkB,EAxDrB,YAwDqB;EAAO;;;;ECoErB;;;;EChJC;EAAQ,cAAA,EAAA,MAAA;EAAA;EACL,eAAT,EAAA,MAAA;EAAO;EACE,cAAA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