MCPcopy Index your code
hub / github.com/nodejs/node / waitFor

Function waitFor

test/common/debugger.js:59–109  ·  view source on GitHub ↗
(pattern)

Source from the content-addressed store, hash-verified

57 },
58
59 waitFor(pattern) {
60 function checkPattern(str) {
61 if (Array.isArray(pattern)) {
62 return pattern.every((p) => p.test(str));
63 }
64 return pattern.test(str);
65 }
66
67 return new Promise((resolve, reject) => {
68 function checkOutput() {
69 if (checkPattern(getOutput())) {
70 tearDown();
71 resolve();
72 }
73 }
74
75 function onChildClose(code, signal) {
76 tearDown();
77 let message = 'Child exited';
78 if (code) {
79 message += `, code ${code}`;
80 }
81 if (signal) {
82 message += `, signal ${signal}`;
83 }
84 message += ` while waiting for ${pattern}; found: ${this.output}`;
85 if (stderrOutput) {
86 message += `\n STDERR: ${stderrOutput}`;
87 }
88 reject(new Error(message));
89 }
90
91 // Capture stack trace here to show where waitFor was called from when it times out.
92 const timeoutErr = new Error(`Timeout (${TIMEOUT}) while waiting for ${pattern}`);
93 const timer = setTimeout(() => {
94 tearDown();
95 timeoutErr.output = this.output;
96 reject(timeoutErr);
97 }, TIMEOUT);
98
99 function tearDown() {
100 clearTimeout(timer);
101 child.stdout.removeListener('data', checkOutput);
102 child.removeListener('close', onChildClose);
103 }
104
105 child.on('close', onChildClose);
106 child.stdout.on('data', checkOutput);
107 checkOutput();
108 });
109 },
110
111 waitForPrompt() {
112 return this.waitFor(/>\s+$/);

Callers

nothing calls this directly

Calls 5

tearDownFunction · 0.70
checkOutputFunction · 0.70
setTimeoutFunction · 0.50
rejectFunction · 0.50
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…