MCPcopy Create free account
hub / github.com/nodejs/node / testMergeTwoSources

Function testMergeTwoSources

test/parallel/test-stream-iter-consumers-merge.js:20–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18// =============================================================================
19
20async function testMergeTwoSources() {
21 const { writer: w1, readable: r1 } = push();
22 const { writer: w2, readable: r2 } = push();
23
24 w1.write('from-a');
25 w1.end();
26 w2.write('from-b');
27 w2.end();
28
29 const merged = merge(r1, r2);
30 const chunks = [];
31 for await (const batch of merged) {
32 for (const chunk of batch) {
33 chunks.push(new TextDecoder().decode(chunk));
34 }
35 }
36
37 // Both sources should be present (order is temporal, not guaranteed)
38 assert.strictEqual(chunks.length, 2);
39 assert.ok(chunks.includes('from-a'));
40 assert.ok(chunks.includes('from-b'));
41}
42
43async function testMergeSingleSource() {
44 const data = await text(merge(from('only-one')));

Calls 8

includesMethod · 0.80
pushFunction · 0.70
decodeMethod · 0.65
mergeFunction · 0.50
writeMethod · 0.45
endMethod · 0.45
pushMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected