11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst { 51cb0ef41Sopenharmony_ci Readable, 61cb0ef41Sopenharmony_ci} = require('stream'); 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst { once } = require('events'); 91cb0ef41Sopenharmony_ciconst { setTimeout } = require('timers/promises'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cifunction createDependentPromises(n) { 121cb0ef41Sopenharmony_ci const promiseAndResolveArray = []; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) { 151cb0ef41Sopenharmony_ci let res; 161cb0ef41Sopenharmony_ci const promise = new Promise((resolve) => { 171cb0ef41Sopenharmony_ci if (i === 0) { 181cb0ef41Sopenharmony_ci res = resolve; 191cb0ef41Sopenharmony_ci return; 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci res = () => promiseAndResolveArray[i - 1][0].then(resolve); 221cb0ef41Sopenharmony_ci }); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci promiseAndResolveArray.push([promise, res]); 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci return promiseAndResolveArray; 281cb0ef41Sopenharmony_ci} 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci{ 311cb0ef41Sopenharmony_ci // Map works on synchronous streams with a synchronous mapper 321cb0ef41Sopenharmony_ci const stream = Readable.from([1, 2, 3, 4, 5]).map((x) => x + x); 331cb0ef41Sopenharmony_ci (async () => { 341cb0ef41Sopenharmony_ci assert.deepStrictEqual(await stream.toArray(), [2, 4, 6, 8, 10]); 351cb0ef41Sopenharmony_ci })().then(common.mustCall()); 361cb0ef41Sopenharmony_ci} 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci{ 391cb0ef41Sopenharmony_ci // Map works on synchronous streams with an asynchronous mapper 401cb0ef41Sopenharmony_ci const stream = Readable.from([1, 2, 3, 4, 5]).map(async (x) => { 411cb0ef41Sopenharmony_ci await Promise.resolve(); 421cb0ef41Sopenharmony_ci return x + x; 431cb0ef41Sopenharmony_ci }); 441cb0ef41Sopenharmony_ci (async () => { 451cb0ef41Sopenharmony_ci assert.deepStrictEqual(await stream.toArray(), [2, 4, 6, 8, 10]); 461cb0ef41Sopenharmony_ci })().then(common.mustCall()); 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci{ 501cb0ef41Sopenharmony_ci // Map works on asynchronous streams with a asynchronous mapper 511cb0ef41Sopenharmony_ci const stream = Readable.from([1, 2, 3, 4, 5]).map(async (x) => { 521cb0ef41Sopenharmony_ci return x + x; 531cb0ef41Sopenharmony_ci }).map((x) => x + x); 541cb0ef41Sopenharmony_ci (async () => { 551cb0ef41Sopenharmony_ci assert.deepStrictEqual(await stream.toArray(), [4, 8, 12, 16, 20]); 561cb0ef41Sopenharmony_ci })().then(common.mustCall()); 571cb0ef41Sopenharmony_ci} 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci{ 601cb0ef41Sopenharmony_ci // Map works on an infinite stream 611cb0ef41Sopenharmony_ci const stream = Readable.from(async function* () { 621cb0ef41Sopenharmony_ci while (true) yield 1; 631cb0ef41Sopenharmony_ci }()).map(common.mustCall(async (x) => { 641cb0ef41Sopenharmony_ci return x + x; 651cb0ef41Sopenharmony_ci }, 5)); 661cb0ef41Sopenharmony_ci (async () => { 671cb0ef41Sopenharmony_ci let i = 1; 681cb0ef41Sopenharmony_ci for await (const item of stream) { 691cb0ef41Sopenharmony_ci assert.strictEqual(item, 2); 701cb0ef41Sopenharmony_ci if (++i === 5) break; 711cb0ef41Sopenharmony_ci } 721cb0ef41Sopenharmony_ci })().then(common.mustCall()); 731cb0ef41Sopenharmony_ci} 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci{ 761cb0ef41Sopenharmony_ci // Map works on non-objectMode streams 771cb0ef41Sopenharmony_ci const stream = new Readable({ 781cb0ef41Sopenharmony_ci read() { 791cb0ef41Sopenharmony_ci this.push(Uint8Array.from([1])); 801cb0ef41Sopenharmony_ci this.push(Uint8Array.from([2])); 811cb0ef41Sopenharmony_ci this.push(null); 821cb0ef41Sopenharmony_ci } 831cb0ef41Sopenharmony_ci }).map(async ([x]) => { 841cb0ef41Sopenharmony_ci return x + x; 851cb0ef41Sopenharmony_ci }).map((x) => x + x); 861cb0ef41Sopenharmony_ci const result = [4, 8]; 871cb0ef41Sopenharmony_ci (async () => { 881cb0ef41Sopenharmony_ci for await (const item of stream) { 891cb0ef41Sopenharmony_ci assert.strictEqual(item, result.shift()); 901cb0ef41Sopenharmony_ci } 911cb0ef41Sopenharmony_ci })().then(common.mustCall()); 921cb0ef41Sopenharmony_ci} 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ci{ 951cb0ef41Sopenharmony_ci // Does not care about data events 961cb0ef41Sopenharmony_ci const source = new Readable({ 971cb0ef41Sopenharmony_ci read() { 981cb0ef41Sopenharmony_ci this.push(Uint8Array.from([1])); 991cb0ef41Sopenharmony_ci this.push(Uint8Array.from([2])); 1001cb0ef41Sopenharmony_ci this.push(null); 1011cb0ef41Sopenharmony_ci } 1021cb0ef41Sopenharmony_ci }); 1031cb0ef41Sopenharmony_ci setImmediate(() => stream.emit('data', Uint8Array.from([1]))); 1041cb0ef41Sopenharmony_ci const stream = source.map(async ([x]) => { 1051cb0ef41Sopenharmony_ci return x + x; 1061cb0ef41Sopenharmony_ci }).map((x) => x + x); 1071cb0ef41Sopenharmony_ci const result = [4, 8]; 1081cb0ef41Sopenharmony_ci (async () => { 1091cb0ef41Sopenharmony_ci for await (const item of stream) { 1101cb0ef41Sopenharmony_ci assert.strictEqual(item, result.shift()); 1111cb0ef41Sopenharmony_ci } 1121cb0ef41Sopenharmony_ci })().then(common.mustCall()); 1131cb0ef41Sopenharmony_ci} 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci{ 1161cb0ef41Sopenharmony_ci // Emitting an error during `map` 1171cb0ef41Sopenharmony_ci const stream = Readable.from([1, 2, 3, 4, 5]).map(async (x) => { 1181cb0ef41Sopenharmony_ci if (x === 3) { 1191cb0ef41Sopenharmony_ci stream.emit('error', new Error('boom')); 1201cb0ef41Sopenharmony_ci } 1211cb0ef41Sopenharmony_ci return x + x; 1221cb0ef41Sopenharmony_ci }); 1231cb0ef41Sopenharmony_ci assert.rejects( 1241cb0ef41Sopenharmony_ci stream.map((x) => x + x).toArray(), 1251cb0ef41Sopenharmony_ci /boom/, 1261cb0ef41Sopenharmony_ci ).then(common.mustCall()); 1271cb0ef41Sopenharmony_ci} 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_ci{ 1301cb0ef41Sopenharmony_ci // Throwing an error during `map` (sync) 1311cb0ef41Sopenharmony_ci const stream = Readable.from([1, 2, 3, 4, 5]).map((x) => { 1321cb0ef41Sopenharmony_ci if (x === 3) { 1331cb0ef41Sopenharmony_ci throw new Error('boom'); 1341cb0ef41Sopenharmony_ci } 1351cb0ef41Sopenharmony_ci return x + x; 1361cb0ef41Sopenharmony_ci }); 1371cb0ef41Sopenharmony_ci assert.rejects( 1381cb0ef41Sopenharmony_ci stream.map((x) => x + x).toArray(), 1391cb0ef41Sopenharmony_ci /boom/, 1401cb0ef41Sopenharmony_ci ).then(common.mustCall()); 1411cb0ef41Sopenharmony_ci} 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ci 1441cb0ef41Sopenharmony_ci{ 1451cb0ef41Sopenharmony_ci // Throwing an error during `map` (async) 1461cb0ef41Sopenharmony_ci const stream = Readable.from([1, 2, 3, 4, 5]).map(async (x) => { 1471cb0ef41Sopenharmony_ci if (x === 3) { 1481cb0ef41Sopenharmony_ci throw new Error('boom'); 1491cb0ef41Sopenharmony_ci } 1501cb0ef41Sopenharmony_ci return x + x; 1511cb0ef41Sopenharmony_ci }); 1521cb0ef41Sopenharmony_ci assert.rejects( 1531cb0ef41Sopenharmony_ci stream.map((x) => x + x).toArray(), 1541cb0ef41Sopenharmony_ci /boom/, 1551cb0ef41Sopenharmony_ci ).then(common.mustCall()); 1561cb0ef41Sopenharmony_ci} 1571cb0ef41Sopenharmony_ci 1581cb0ef41Sopenharmony_ci{ 1591cb0ef41Sopenharmony_ci // Concurrency + AbortSignal 1601cb0ef41Sopenharmony_ci const ac = new AbortController(); 1611cb0ef41Sopenharmony_ci const range = Readable.from([1, 2, 3, 4, 5]); 1621cb0ef41Sopenharmony_ci const stream = range.map(common.mustCall(async (_, { signal }) => { 1631cb0ef41Sopenharmony_ci await once(signal, 'abort'); 1641cb0ef41Sopenharmony_ci throw signal.reason; 1651cb0ef41Sopenharmony_ci }, 2), { signal: ac.signal, concurrency: 2, highWaterMark: 0 }); 1661cb0ef41Sopenharmony_ci // pump 1671cb0ef41Sopenharmony_ci assert.rejects(async () => { 1681cb0ef41Sopenharmony_ci for await (const item of stream) { 1691cb0ef41Sopenharmony_ci assert.fail('should not reach here, got ' + item); 1701cb0ef41Sopenharmony_ci } 1711cb0ef41Sopenharmony_ci }, { 1721cb0ef41Sopenharmony_ci name: 'AbortError', 1731cb0ef41Sopenharmony_ci }).then(common.mustCall()); 1741cb0ef41Sopenharmony_ci 1751cb0ef41Sopenharmony_ci setImmediate(() => { 1761cb0ef41Sopenharmony_ci ac.abort(); 1771cb0ef41Sopenharmony_ci }); 1781cb0ef41Sopenharmony_ci} 1791cb0ef41Sopenharmony_ci 1801cb0ef41Sopenharmony_ci{ 1811cb0ef41Sopenharmony_ci // Concurrency result order 1821cb0ef41Sopenharmony_ci const stream = Readable.from([1, 2]).map(async (item, { signal }) => { 1831cb0ef41Sopenharmony_ci await setTimeout(10 - item, { signal }); 1841cb0ef41Sopenharmony_ci return item; 1851cb0ef41Sopenharmony_ci }, { concurrency: 2 }); 1861cb0ef41Sopenharmony_ci 1871cb0ef41Sopenharmony_ci (async () => { 1881cb0ef41Sopenharmony_ci const expected = [1, 2]; 1891cb0ef41Sopenharmony_ci for await (const item of stream) { 1901cb0ef41Sopenharmony_ci assert.strictEqual(item, expected.shift()); 1911cb0ef41Sopenharmony_ci } 1921cb0ef41Sopenharmony_ci })().then(common.mustCall()); 1931cb0ef41Sopenharmony_ci} 1941cb0ef41Sopenharmony_ci 1951cb0ef41Sopenharmony_ci 1961cb0ef41Sopenharmony_ci{ 1971cb0ef41Sopenharmony_ci // highWaterMark with small concurrency 1981cb0ef41Sopenharmony_ci const finishOrder = []; 1991cb0ef41Sopenharmony_ci 2001cb0ef41Sopenharmony_ci const promises = createDependentPromises(4); 2011cb0ef41Sopenharmony_ci 2021cb0ef41Sopenharmony_ci const raw = Readable.from([2, 0, 1, 3]); 2031cb0ef41Sopenharmony_ci const stream = raw.map(async (item) => { 2041cb0ef41Sopenharmony_ci const [promise, resolve] = promises[item]; 2051cb0ef41Sopenharmony_ci resolve(); 2061cb0ef41Sopenharmony_ci 2071cb0ef41Sopenharmony_ci await promise; 2081cb0ef41Sopenharmony_ci finishOrder.push(item); 2091cb0ef41Sopenharmony_ci return item; 2101cb0ef41Sopenharmony_ci }, { concurrency: 2 }); 2111cb0ef41Sopenharmony_ci 2121cb0ef41Sopenharmony_ci (async () => { 2131cb0ef41Sopenharmony_ci await stream.toArray(); 2141cb0ef41Sopenharmony_ci 2151cb0ef41Sopenharmony_ci assert.deepStrictEqual(finishOrder, [0, 1, 2, 3]); 2161cb0ef41Sopenharmony_ci })().then(common.mustCall(), common.mustNotCall()); 2171cb0ef41Sopenharmony_ci} 2181cb0ef41Sopenharmony_ci 2191cb0ef41Sopenharmony_ci{ 2201cb0ef41Sopenharmony_ci // highWaterMark with a lot of items and large concurrency 2211cb0ef41Sopenharmony_ci const finishOrder = []; 2221cb0ef41Sopenharmony_ci 2231cb0ef41Sopenharmony_ci const promises = createDependentPromises(20); 2241cb0ef41Sopenharmony_ci 2251cb0ef41Sopenharmony_ci const input = [10, 1, 0, 3, 4, 2, 5, 7, 8, 9, 6, 11, 12, 13, 18, 15, 16, 17, 14, 19]; 2261cb0ef41Sopenharmony_ci const raw = Readable.from(input); 2271cb0ef41Sopenharmony_ci // Should be 2281cb0ef41Sopenharmony_ci // 10, 1, 0, 3, 4, 2 | next: 0 2291cb0ef41Sopenharmony_ci // 10, 1, 3, 4, 2, 5 | next: 1 2301cb0ef41Sopenharmony_ci // 10, 3, 4, 2, 5, 7 | next: 2 2311cb0ef41Sopenharmony_ci // 10, 3, 4, 5, 7, 8 | next: 3 2321cb0ef41Sopenharmony_ci // 10, 4, 5, 7, 8, 9 | next: 4 2331cb0ef41Sopenharmony_ci // 10, 5, 7, 8, 9, 6 | next: 5 2341cb0ef41Sopenharmony_ci // 10, 7, 8, 9, 6, 11 | next: 6 2351cb0ef41Sopenharmony_ci // 10, 7, 8, 9, 11, 12 | next: 7 2361cb0ef41Sopenharmony_ci // 10, 8, 9, 11, 12, 13 | next: 8 2371cb0ef41Sopenharmony_ci // 10, 9, 11, 12, 13, 18 | next: 9 2381cb0ef41Sopenharmony_ci // 10, 11, 12, 13, 18, 15 | next: 10 2391cb0ef41Sopenharmony_ci // 11, 12, 13, 18, 15, 16 | next: 11 2401cb0ef41Sopenharmony_ci // 12, 13, 18, 15, 16, 17 | next: 12 2411cb0ef41Sopenharmony_ci // 13, 18, 15, 16, 17, 14 | next: 13 2421cb0ef41Sopenharmony_ci // 18, 15, 16, 17, 14, 19 | next: 14 2431cb0ef41Sopenharmony_ci // 18, 15, 16, 17, 19 | next: 15 2441cb0ef41Sopenharmony_ci // 18, 16, 17, 19 | next: 16 2451cb0ef41Sopenharmony_ci // 18, 17, 19 | next: 17 2461cb0ef41Sopenharmony_ci // 18, 19 | next: 18 2471cb0ef41Sopenharmony_ci // 19 | next: 19 2481cb0ef41Sopenharmony_ci // 2491cb0ef41Sopenharmony_ci 2501cb0ef41Sopenharmony_ci const stream = raw.map(async (item) => { 2511cb0ef41Sopenharmony_ci const [promise, resolve] = promises[item]; 2521cb0ef41Sopenharmony_ci resolve(); 2531cb0ef41Sopenharmony_ci 2541cb0ef41Sopenharmony_ci await promise; 2551cb0ef41Sopenharmony_ci finishOrder.push(item); 2561cb0ef41Sopenharmony_ci return item; 2571cb0ef41Sopenharmony_ci }, { concurrency: 6 }); 2581cb0ef41Sopenharmony_ci 2591cb0ef41Sopenharmony_ci (async () => { 2601cb0ef41Sopenharmony_ci const outputOrder = await stream.toArray(); 2611cb0ef41Sopenharmony_ci 2621cb0ef41Sopenharmony_ci assert.deepStrictEqual(outputOrder, input); 2631cb0ef41Sopenharmony_ci assert.deepStrictEqual(finishOrder, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]); 2641cb0ef41Sopenharmony_ci })().then(common.mustCall(), common.mustNotCall()); 2651cb0ef41Sopenharmony_ci} 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_ci{ 2681cb0ef41Sopenharmony_ci // Custom highWaterMark with a lot of items and large concurrency 2691cb0ef41Sopenharmony_ci const finishOrder = []; 2701cb0ef41Sopenharmony_ci 2711cb0ef41Sopenharmony_ci const promises = createDependentPromises(20); 2721cb0ef41Sopenharmony_ci 2731cb0ef41Sopenharmony_ci const input = [11, 1, 0, 3, 4, 2, 5, 7, 8, 9, 6, 10, 12, 13, 18, 15, 16, 17, 14, 19]; 2741cb0ef41Sopenharmony_ci const raw = Readable.from(input); 2751cb0ef41Sopenharmony_ci // Should be 2761cb0ef41Sopenharmony_ci // 11, 1, 0, 3, 4 | next: 0, buffer: [] 2771cb0ef41Sopenharmony_ci // 11, 1, 3, 4, 2 | next: 1, buffer: [0] 2781cb0ef41Sopenharmony_ci // 11, 3, 4, 2, 5 | next: 2, buffer: [0, 1] 2791cb0ef41Sopenharmony_ci // 11, 3, 4, 5, 7 | next: 3, buffer: [0, 1, 2] 2801cb0ef41Sopenharmony_ci // 11, 4, 5, 7, 8 | next: 4, buffer: [0, 1, 2, 3] 2811cb0ef41Sopenharmony_ci // 11, 5, 7, 8, 9 | next: 5, buffer: [0, 1, 2, 3, 4] 2821cb0ef41Sopenharmony_ci // 11, 7, 8, 9, 6 | next: 6, buffer: [0, 1, 2, 3, 4, 5] 2831cb0ef41Sopenharmony_ci // 11, 7, 8, 9, 10 | next: 7, buffer: [0, 1, 2, 3, 4, 5, 6] -- buffer full 2841cb0ef41Sopenharmony_ci // 11, 8, 9, 10, 12 | next: 8, buffer: [0, 1, 2, 3, 4, 5, 6] 2851cb0ef41Sopenharmony_ci // 11, 9, 10, 12, 13 | next: 9, buffer: [0, 1, 2, 3, 4, 5, 6] 2861cb0ef41Sopenharmony_ci // 11, 10, 12, 13, 18 | next: 10, buffer: [0, 1, 2, 3, 4, 5, 6] 2871cb0ef41Sopenharmony_ci // 11, 12, 13, 18, 15 | next: 11, buffer: [0, 1, 2, 3, 4, 5, 6] 2881cb0ef41Sopenharmony_ci // 12, 13, 18, 15, 16 | next: 12, buffer: [] -- all items flushed as 11 is consumed and all the items wait for it 2891cb0ef41Sopenharmony_ci // 13, 18, 15, 16, 17 | next: 13, buffer: [] 2901cb0ef41Sopenharmony_ci // 18, 15, 16, 17, 14 | next: 14, buffer: [] 2911cb0ef41Sopenharmony_ci // 18, 15, 16, 17, 19 | next: 15, buffer: [14] 2921cb0ef41Sopenharmony_ci // 18, 16, 17, 19 | next: 16, buffer: [14, 15] 2931cb0ef41Sopenharmony_ci // 18, 17, 19 | next: 17, buffer: [14, 15, 16] 2941cb0ef41Sopenharmony_ci // 18, 19 | next: 18, buffer: [14, 15, 16, 17] 2951cb0ef41Sopenharmony_ci // 19 | next: 19, buffer: [] -- all items flushed 2961cb0ef41Sopenharmony_ci // 2971cb0ef41Sopenharmony_ci 2981cb0ef41Sopenharmony_ci const stream = raw.map(async (item) => { 2991cb0ef41Sopenharmony_ci const [promise, resolve] = promises[item]; 3001cb0ef41Sopenharmony_ci resolve(); 3011cb0ef41Sopenharmony_ci 3021cb0ef41Sopenharmony_ci await promise; 3031cb0ef41Sopenharmony_ci finishOrder.push(item); 3041cb0ef41Sopenharmony_ci return item; 3051cb0ef41Sopenharmony_ci }, { concurrency: 5, highWaterMark: 7 }); 3061cb0ef41Sopenharmony_ci 3071cb0ef41Sopenharmony_ci (async () => { 3081cb0ef41Sopenharmony_ci const outputOrder = await stream.toArray(); 3091cb0ef41Sopenharmony_ci 3101cb0ef41Sopenharmony_ci assert.deepStrictEqual(outputOrder, input); 3111cb0ef41Sopenharmony_ci assert.deepStrictEqual(finishOrder, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]); 3121cb0ef41Sopenharmony_ci })().then(common.mustCall(), common.mustNotCall()); 3131cb0ef41Sopenharmony_ci} 3141cb0ef41Sopenharmony_ci 3151cb0ef41Sopenharmony_ci{ 3161cb0ef41Sopenharmony_ci // Where there is a delay between the first and the next item it should not wait for filled queue 3171cb0ef41Sopenharmony_ci // before yielding to the user 3181cb0ef41Sopenharmony_ci const promises = createDependentPromises(3); 3191cb0ef41Sopenharmony_ci 3201cb0ef41Sopenharmony_ci const raw = Readable.from([0, 1, 2]); 3211cb0ef41Sopenharmony_ci 3221cb0ef41Sopenharmony_ci const stream = raw 3231cb0ef41Sopenharmony_ci .map(async (item) => { 3241cb0ef41Sopenharmony_ci if (item !== 0) { 3251cb0ef41Sopenharmony_ci await promises[item][0]; 3261cb0ef41Sopenharmony_ci } 3271cb0ef41Sopenharmony_ci 3281cb0ef41Sopenharmony_ci return item; 3291cb0ef41Sopenharmony_ci }, { concurrency: 2 }) 3301cb0ef41Sopenharmony_ci .map((item) => { 3311cb0ef41Sopenharmony_ci // eslint-disable-next-line no-unused-vars 3321cb0ef41Sopenharmony_ci for (const [_, resolve] of promises) { 3331cb0ef41Sopenharmony_ci resolve(); 3341cb0ef41Sopenharmony_ci } 3351cb0ef41Sopenharmony_ci 3361cb0ef41Sopenharmony_ci return item; 3371cb0ef41Sopenharmony_ci }); 3381cb0ef41Sopenharmony_ci 3391cb0ef41Sopenharmony_ci (async () => { 3401cb0ef41Sopenharmony_ci await stream.toArray(); 3411cb0ef41Sopenharmony_ci })().then(common.mustCall(), common.mustNotCall()); 3421cb0ef41Sopenharmony_ci} 3431cb0ef41Sopenharmony_ci 3441cb0ef41Sopenharmony_ci{ 3451cb0ef41Sopenharmony_ci // Error cases 3461cb0ef41Sopenharmony_ci assert.throws(() => Readable.from([1]).map(1), /ERR_INVALID_ARG_TYPE/); 3471cb0ef41Sopenharmony_ci assert.throws(() => Readable.from([1]).map((x) => x, { 3481cb0ef41Sopenharmony_ci concurrency: 'Foo' 3491cb0ef41Sopenharmony_ci }), /ERR_OUT_OF_RANGE/); 3501cb0ef41Sopenharmony_ci assert.throws(() => Readable.from([1]).map((x) => x, { 3511cb0ef41Sopenharmony_ci concurrency: -1 3521cb0ef41Sopenharmony_ci }), /ERR_OUT_OF_RANGE/); 3531cb0ef41Sopenharmony_ci assert.throws(() => Readable.from([1]).map((x) => x, 1), /ERR_INVALID_ARG_TYPE/); 3541cb0ef41Sopenharmony_ci assert.throws(() => Readable.from([1]).map((x) => x, { signal: true }), /ERR_INVALID_ARG_TYPE/); 3551cb0ef41Sopenharmony_ci} 3561cb0ef41Sopenharmony_ci{ 3571cb0ef41Sopenharmony_ci // Test result is a Readable 3581cb0ef41Sopenharmony_ci const stream = Readable.from([1, 2, 3, 4, 5]).map((x) => x); 3591cb0ef41Sopenharmony_ci assert.strictEqual(stream.readable, true); 3601cb0ef41Sopenharmony_ci} 361