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

Function runWriteSucceed

test/sequential/test-watch-mode-worker.mjs:39–88  ·  view source on GitHub ↗
({
  file,
  watchedFile,
  watchFlag = '--watch',
  args = [file],
  completed = 'Completed running',
  restarts = 2,
  options = {},
  shouldFail = false,
})

Source from the content-addressed store, hash-verified

37}
38
39async function runWriteSucceed({
40 file,
41 watchedFile,
42 watchFlag = '--watch',
43 args = [file],
44 completed = 'Completed running',
45 restarts = 2,
46 options = {},
47 shouldFail = false,
48}) {
49 args.unshift('--no-warnings');
50 if (watchFlag !== null) args.unshift(watchFlag);
51
52 const child = spawn(execPath, args, { encoding: 'utf8', stdio: 'pipe', ...options });
53
54 let completes = 0;
55 let cancelRestarts = () => {};
56 let stderr = '';
57 const stdout = [];
58
59 child.stderr.on('data', (data) => {
60 stderr += data;
61 });
62
63 try {
64 for await (const data of createInterface({ input: child.stdout })) {
65 if (!data.startsWith('Waiting for graceful termination') &&
66 !data.startsWith('Gracefully restarted')) {
67 stdout.push(data);
68 }
69
70 if (data.startsWith(completed)) {
71 completes++;
72
73 if (completes === restarts) break;
74
75 if (completes === 1) {
76 cancelRestarts = restart(watchedFile);
77 }
78 }
79
80 if (!shouldFail && data.startsWith('Failed running')) break;
81 }
82 } finally {
83 child.kill();
84 cancelRestarts();
85 }
86
87 return { stdout, stderr, pid: child.pid };
88}
89
90tmpdir.refresh();
91

Callers 1

Calls 8

unshiftMethod · 0.80
killMethod · 0.80
restartFunction · 0.70
cancelRestartsFunction · 0.70
spawnFunction · 0.50
createInterfaceFunction · 0.50
onMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected