| 63 | |
| 64 | // Line-buffered streaming so prefixed lines stay intact across chunk boundaries. |
| 65 | const streamLines = (stream, sink) => { |
| 66 | let buffer = ''; |
| 67 | stream.on('data', (chunk) => { |
| 68 | buffer += chunk.toString(); |
| 69 | const lines = buffer.split('\n'); |
| 70 | buffer = lines.pop(); |
| 71 | for (const line of lines) { |
| 72 | if (line === '') continue; |
| 73 | |
| 74 | if (!line.startsWith('[')) { |
| 75 | if (!seenFirst) { |
| 76 | console.log( |
| 77 | `${colors.red('[fatal]')} test ${colors.yellow( |
| 78 | `[${dir.name}]`, |
| 79 | )} did not call "initialize(import.meta.url)"!`, |
| 80 | ); |
| 81 | worker.terminate(); |
| 82 | return; |
| 83 | } |
| 84 | deferredOnSuccess.push(line); |
| 85 | continue; |
| 86 | } |
| 87 | |
| 88 | seenFirst = true; |
| 89 | sink(`${prefix}${line}`); |
| 90 | } |
| 91 | }); |
| 92 | stream.on('end', () => { |
| 93 | if (buffer !== '') sink(`${prefix}${buffer}`); |
| 94 | }); |
| 95 | }; |
| 96 | |
| 97 | streamLines(worker.stdout, (line) => console.log(line)); |
| 98 | streamLines(worker.stderr, (line) => console.error(line)); |