@forwardimpact/libutil 0.1.72 → 0.1.73

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/test/wait.test.js DELETED
@@ -1,109 +0,0 @@
1
- import { describe, test } from "node:test";
2
- import assert from "node:assert";
3
-
4
- import { waitFor } from "../wait.js";
5
-
6
- const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7
-
8
- describe("waitFor", () => {
9
- test("throws if delayFn is missing", async () => {
10
- await assert.rejects(
11
- () => waitFor(() => Promise.resolve(true), {}),
12
- /delayFn is required/,
13
- );
14
- });
15
-
16
- test("resolves immediately when condition is true", async () => {
17
- let callCount = 0;
18
- await waitFor(
19
- () => {
20
- callCount++;
21
- return Promise.resolve(true);
22
- },
23
- {},
24
- delay,
25
- );
26
-
27
- assert.strictEqual(callCount, 1);
28
- });
29
-
30
- test("retries until condition becomes true", async () => {
31
- let callCount = 0;
32
- await waitFor(
33
- () => {
34
- callCount++;
35
- return Promise.resolve(callCount >= 3);
36
- },
37
- { interval: 10, timeout: 5000 },
38
- delay,
39
- );
40
-
41
- assert.strictEqual(callCount, 3);
42
- });
43
-
44
- test("throws error on timeout", async () => {
45
- await assert.rejects(
46
- () =>
47
- waitFor(
48
- () => Promise.resolve(false),
49
- { timeout: 50, interval: 10 },
50
- delay,
51
- ),
52
- { message: "Timeout waiting for condition after 50ms" },
53
- );
54
- });
55
-
56
- test("ignores errors during polling", async () => {
57
- let callCount = 0;
58
- await waitFor(
59
- () => {
60
- callCount++;
61
- if (callCount < 3) {
62
- throw new Error("Service not ready");
63
- }
64
- return Promise.resolve(true);
65
- },
66
- { interval: 10, timeout: 5000 },
67
- delay,
68
- );
69
-
70
- assert.strictEqual(callCount, 3);
71
- });
72
-
73
- test("uses default options when not provided", async () => {
74
- let called = false;
75
- await waitFor(
76
- () => {
77
- called = true;
78
- return Promise.resolve(true);
79
- },
80
- {},
81
- delay,
82
- );
83
-
84
- assert.strictEqual(called, true);
85
- });
86
-
87
- test("increases interval with exponential backoff", async () => {
88
- const intervals = [];
89
- let lastTime = Date.now();
90
- let callCount = 0;
91
-
92
- await waitFor(
93
- () => {
94
- const now = Date.now();
95
- if (callCount > 0) {
96
- intervals.push(now - lastTime);
97
- }
98
- lastTime = now;
99
- callCount++;
100
- return Promise.resolve(callCount >= 4);
101
- },
102
- { interval: 20, maxInterval: 100, timeout: 5000 },
103
- delay,
104
- );
105
-
106
- // Intervals should generally increase (with some tolerance for timing)
107
- assert.ok(intervals.length >= 2);
108
- });
109
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes