( command: string, tmpDir: string, criteria: (output: string) => boolean )
| 97 | } |
| 98 | |
| 99 | export function runCommandUntil( |
| 100 | command: string, |
| 101 | tmpDir: string, |
| 102 | criteria: (output: string) => boolean |
| 103 | ): Promise<ChildProcess> { |
| 104 | const p = exec(command, { |
| 105 | cwd: tmpDir, |
| 106 | encoding: 'utf-8', |
| 107 | }); |
| 108 | registerExecutedChildProcess(p); |
| 109 | return new Promise<ChildProcess>((res, rej) => { |
| 110 | let output = ''; |
| 111 | let complete = false; |
| 112 | |
| 113 | function checkCriteria(c: any) { |
| 114 | output += c.toString(); |
| 115 | console.warn(output); |
| 116 | if (criteria(stripConsoleColors(output)) && !complete) { |
| 117 | complete = true; |
| 118 | res(p); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | p.stdout?.on('data', checkCriteria); |
| 123 | p.stderr?.on('data', checkCriteria); |
| 124 | p.on('exit', (code) => { |
| 125 | if (!complete) { |
| 126 | rej(`Exited with ${code}`); |
| 127 | } else { |
| 128 | res(p); |
| 129 | } |
| 130 | }); |
| 131 | }); |
| 132 | } |
| 133 | |
| 134 | function stripConsoleColors(log: string): string { |
| 135 | return log.replace( |
no test coverage detected
searching dependent graphs…