({
file,
watchedFile,
watchFlag = '--watch',
args = [file],
completed = 'Completed running',
restarts = 2,
options = {},
shouldFail = false,
})
| 37 | } |
| 38 | |
| 39 | async 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 | |
| 90 | tmpdir.refresh(); |
| 91 |
no test coverage detected