MCPcopy
hub / github.com/nestjs/nest / waitForReplToStart

Function waitForReplToStart

integration/repl/e2e/repl-process.spec.ts:16–43  ·  view source on GitHub ↗
(
    process: ReturnType<typeof spawn>,
    message,
    timeout = 10000,
  )

Source from the content-addressed store, hash-verified

14 let replProcess: ReturnType<typeof spawn>;
15
16 function waitForReplToStart(
17 process: ReturnType<typeof spawn>,
18 message,
19 timeout = 10000,
20 ): Promise<void> {
21 return new Promise((resolve, reject) => {
22 const timer = setTimeout(() => {
23 reject(new Error('REPL did not start in time'));
24 }, timeout);
25
26 if (!process.stdout || !process.stderr) {
27 return reject(new Error('REPL stdout or stderr is not available'));
28 }
29 process.stdout.on('data', data => {
30 if (data.toString().includes(message)) {
31 clearTimeout(timer);
32 resolve();
33 }
34 });
35
36 process.stderr.on('data', data => {
37 if (data.toString().includes(message)) {
38 clearTimeout(timer);
39 reject(new Error(`REPL started with error: ${data}`));
40 }
41 });
42 });
43 }
44
45 beforeEach(async function () {
46 this.timeout(15000);

Callers 1

Calls 3

onMethod · 0.65
setTimeoutFunction · 0.50
toStringMethod · 0.45

Tested by

no test coverage detected