MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / waitFor

Function waitFor

__tests__/watcher.test.ts:41–55  ·  view source on GitHub ↗

* Helper to wait for a condition with timeout. Used for assertions that depend * on the debounce timer (real setTimeout) firing, or on the real watcher's * event delivery in the end-to-end test.

(
  condition: () => boolean,
  timeoutMs = 2000,
  intervalMs = 25
)

Source from the content-addressed store, hash-verified

39 * event delivery in the end-to-end test.
40 */
41function waitFor(
42 condition: () => boolean,
43 timeoutMs = 2000,
44 intervalMs = 25
45): Promise<void> {
46 return new Promise((resolve, reject) => {
47 const start = Date.now();
48 const check = () => {
49 if (condition()) return resolve();
50 if (Date.now() - start > timeoutMs) return reject(new Error('waitFor timed out'));
51 setTimeout(check, intervalMs);
52 };
53 check();
54 });
55}
56
57describe('FileWatcher', () => {
58 let testDir: string;

Callers 1

watcher.test.tsFile · 0.70

Calls 1

checkFunction · 0.70

Tested by

no test coverage detected