MCPcopy Create free account
hub / github.com/Snapchat/Valdi / monitor

Function monitor

npm_modules/cli/test/helpers/AsyncHelpers.ts:54–92  ·  view source on GitHub ↗
(requiredQueries: (string | RegExp)[])

Source from the content-addressed store, hash-verified

52 const [idleTimer, touch, complete] = timeoutOnIdle(idleTimeoutMs);
53
54 const monitor = (requiredQueries: (string | RegExp)[]) => {
55 let queries = requiredQueries.slice();
56 let onDone: (value: true) => void, onError: (error: Error) => void;
57
58 const promise = new Promise((resolve, reject) => {
59 onDone = resolve;
60 onError = reject;
61
62 // If queries are empty to start with resolve immediately
63 if (queries.length === 0) {
64 resolve(true);
65 }
66 });
67
68 const isDone = () => queries.length === 0;
69
70 return {
71 promise,
72 isDone,
73 onEachLine: onEachLine(line => {
74 touch();
75 queries = queries.filter((query): boolean => {
76 if (typeof query === 'string') {
77 return !line.toString().includes(query);
78 }
79 if (query instanceof RegExp) {
80 return !query.test(line.toString('utf8'));
81 }
82 onError(new Error('invalid query'));
83 return false;
84 });
85
86 if (isDone()) {
87 onDone(true);
88 return;
89 }
90 }),
91 };
92 };
93
94 const stdoutMonitor = monitor(stdout);
95 const stderrMonitor = monitor(stderr);

Callers 1

lookForOutputFunction · 0.85

Calls 8

onEachLineFunction · 0.90
isDoneFunction · 0.85
onDoneFunction · 0.85
filterMethod · 0.80
toStringMethod · 0.65
resolveFunction · 0.50
onErrorFunction · 0.50
testMethod · 0.45

Tested by

no test coverage detected