({
file,
watchedFile,
watchFlag = '--watch',
args = [file],
completed = 'Completed running',
restarts = 2,
options = {},
shouldFail = false,
})
| 104 | } |
| 105 | |
| 106 | async function runWriteSucceed({ |
| 107 | file, |
| 108 | watchedFile, |
| 109 | watchFlag = '--watch', |
| 110 | args = [file], |
| 111 | completed = 'Completed running', |
| 112 | restarts = 2, |
| 113 | options = {}, |
| 114 | shouldFail = false, |
| 115 | }) { |
| 116 | args.unshift('--no-warnings'); |
| 117 | if (watchFlag !== null) args.unshift(watchFlag); |
| 118 | const child = spawn(execPath, args, { encoding: 'utf8', stdio: 'pipe', ...options }); |
| 119 | let completes = 0; |
| 120 | let cancelRestarts = () => {}; |
| 121 | let stderr = ''; |
| 122 | const stdout = []; |
| 123 | |
| 124 | child.stderr.on('data', (data) => { |
| 125 | stderr += data; |
| 126 | }); |
| 127 | |
| 128 | try { |
| 129 | // Break the chunks into lines |
| 130 | for await (const data of createInterface({ input: child.stdout })) { |
| 131 | if (!data.startsWith('Waiting for graceful termination') && !data.startsWith('Gracefully restarted')) { |
| 132 | stdout.push(data); |
| 133 | } |
| 134 | if (data.startsWith(completed)) { |
| 135 | completes++; |
| 136 | if (completes === restarts) { |
| 137 | break; |
| 138 | } |
| 139 | if (completes === 1) { |
| 140 | cancelRestarts = restart(watchedFile); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if (!shouldFail && data.startsWith('Failed running')) { |
| 145 | break; |
| 146 | } |
| 147 | } |
| 148 | } finally { |
| 149 | child.kill(); |
| 150 | cancelRestarts(); |
| 151 | } |
| 152 | return { stdout, stderr, pid: child.pid }; |
| 153 | } |
| 154 | |
| 155 | async function failWriteSucceed({ file, watchedFile }) { |
| 156 | const child = spawn(execPath, ['--watch', '--no-warnings', file], { encoding: 'utf8', stdio: 'pipe' }); |
no test coverage detected
searching dependent graphs…