MCPcopy
hub / github.com/TypeStrong/ts-node / executeInRepl

Function executeInRepl

src/test/repl/helpers.ts:63–93  ·  view source on GitHub ↗
(input: string, options: ExecuteInReplOptions)

Source from the content-addressed store, hash-verified

61 }
62
63 async function executeInRepl(input: string, options: ExecuteInReplOptions) {
64 const {
65 waitPattern,
66 // Wait longer if there's a signal to end it early
67 waitMs = waitPattern != null ? 20e3 : 1e3,
68 startInternalOptions,
69 ...rest
70 } = options;
71 const { stdin, stdout, stderr, replService } = createReplViaApi(rest);
72
73 if (startInternalOptions) {
74 replService.startInternal(startInternalOptions);
75 } else {
76 replService.start();
77 }
78
79 stdin.write(input);
80 stdin.end();
81 const stdoutPromise = getStream(stdout, waitPattern);
82 const stderrPromise = getStream(stderr, waitPattern);
83 // Wait for expected output pattern or timeout, whichever comes first
84 await Promise.race([delay(waitMs), stdoutPromise, stderrPromise]);
85 stdout.end();
86 stderr.end();
87
88 return {
89 stdin,
90 stdout: await stdoutPromise,
91 stderr: await stderrPromise,
92 };
93 }
94}
95
96export const macroReplNoErrorsAndStdoutContains = test.macro(

Callers

nothing calls this directly

Calls 5

getStreamFunction · 0.90
createReplViaApiFunction · 0.85
startInternalMethod · 0.80
startMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…