-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgc.js
More file actions
34 lines (30 loc) · 920 Bytes
/
gc.js
File metadata and controls
34 lines (30 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
if (typeof gc !== 'function') {
throw new Error('Expected a global gc function');
}
if (typeof gcUntil !== 'function') {
throw new Error('Expected a global gcUntil function');
}
// gc should run synchronously without throwing
gc();
// gcUntil should resolve once the condition becomes true
let count = 0;
await gcUntil('test-passes', () => {
count++;
return count >= 2;
});
if (count < 2) {
throw new Error(`Expected condition to be checked at least twice, got ${count}`);
}
// gcUntil should throw after exhausting retries when condition never becomes true
let threw = false;
try {
await gcUntil('test-fails', () => false);
} catch (error) {
threw = true;
if (!error.message.includes('test-fails')) {
throw new Error(`Expected error message to include 'test-fails' but got: ${error.message}`);
}
}
if (!threw) {
throw new Error('gcUntil must throw when the condition never becomes true');
}