|
14 | 14 |
|
15 | 15 | import assert from 'node:assert' |
16 | 16 | import { test, describe, after } from 'node:test' |
17 | | -import { Duplex } from 'node:stream' |
| 17 | +import { Duplex, Readable } from 'node:stream' |
18 | 18 | import { $, chalk, fs, path, dotenv } from '../src/index.ts' |
19 | 19 | import { |
20 | 20 | echo, |
@@ -365,6 +365,34 @@ describe('goods', () => { |
365 | 365 | assert(p3.includes('GitHub')) |
366 | 366 | }) |
367 | 367 |
|
| 368 | + test('responseToReadable propagates reader errors to stream', async () => { |
| 369 | + const error = new Error('stream read failed') |
| 370 | + const mockReader = { |
| 371 | + read: () => Promise.reject(error), |
| 372 | + } |
| 373 | + |
| 374 | + const rs = new Readable({ read() {} }) |
| 375 | + |
| 376 | + // Simulate what responseToReadable does with the fix applied |
| 377 | + rs._read = async () => { |
| 378 | + try { |
| 379 | + const result = await mockReader.read() |
| 380 | + rs.push(result.done ? null : Buffer.from(result.value)) |
| 381 | + } catch (err) { |
| 382 | + rs.destroy(err as Error) |
| 383 | + } |
| 384 | + } |
| 385 | + |
| 386 | + const errorPromise = new Promise<Error>((resolve) => { |
| 387 | + rs.on('error', resolve) |
| 388 | + }) |
| 389 | + |
| 390 | + rs.read() |
| 391 | + |
| 392 | + const receivedError = await errorPromise |
| 393 | + assert.equal(receivedError.message, 'stream read failed') |
| 394 | + }) |
| 395 | + |
368 | 396 | describe('dotenv', () => { |
369 | 397 | test('parse()', () => { |
370 | 398 | assert.deepEqual(dotenv.parse(''), {}) |
|
0 commit comments