| 83 | // ============================================================================= |
| 84 | |
| 85 | async function testBatchingBehavior() { |
| 86 | const readable = new Readable({ |
| 87 | read() { |
| 88 | // Push multiple chunks synchronously so they all buffer |
| 89 | for (let i = 0; i < 10; i++) { |
| 90 | this.push(Buffer.from(`chunk${i}`)); |
| 91 | } |
| 92 | this.push(null); |
| 93 | }, |
| 94 | }); |
| 95 | |
| 96 | const source = from(readable); |
| 97 | const batches = []; |
| 98 | for await (const batch of source) { |
| 99 | batches.push(batch); |
| 100 | } |
| 101 | |
| 102 | // All chunks were buffered synchronously, so they should come out |
| 103 | // as fewer batches than individual chunks (ideally one batch). |
| 104 | assert.ok(batches.length < 10, |
| 105 | `Expected fewer batches than chunks, got ${batches.length}`); |
| 106 | |
| 107 | // Total data should be correct |
| 108 | const allChunks = batches.flat(); |
| 109 | const combined = Buffer.concat(allChunks); |
| 110 | let expected = ''; |
| 111 | for (let i = 0; i < 10; i++) { |
| 112 | expected += `chunk${i}`; |
| 113 | } |
| 114 | assert.strictEqual(combined.toString(), expected); |
| 115 | } |
| 116 | |
| 117 | // ============================================================================= |
| 118 | // Byte-mode Readable: kValidatedSource is set |