11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci'use strict';
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst common = require('../common');
61cb0ef41Sopenharmony_ciconst {
71cb0ef41Sopenharmony_ci  Readable,
81cb0ef41Sopenharmony_ci  Transform,
91cb0ef41Sopenharmony_ci  Writable,
101cb0ef41Sopenharmony_ci  finished,
111cb0ef41Sopenharmony_ci  PassThrough
121cb0ef41Sopenharmony_ci} = require('stream');
131cb0ef41Sopenharmony_ciconst compose = require('internal/streams/compose');
141cb0ef41Sopenharmony_ciconst assert = require('assert');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci{
171cb0ef41Sopenharmony_ci  let res = '';
181cb0ef41Sopenharmony_ci  compose(
191cb0ef41Sopenharmony_ci    new Transform({
201cb0ef41Sopenharmony_ci      transform: common.mustCall((chunk, encoding, callback) => {
211cb0ef41Sopenharmony_ci        callback(null, chunk + chunk);
221cb0ef41Sopenharmony_ci      })
231cb0ef41Sopenharmony_ci    }),
241cb0ef41Sopenharmony_ci    new Transform({
251cb0ef41Sopenharmony_ci      transform: common.mustCall((chunk, encoding, callback) => {
261cb0ef41Sopenharmony_ci        callback(null, chunk.toString().toUpperCase());
271cb0ef41Sopenharmony_ci      })
281cb0ef41Sopenharmony_ci    })
291cb0ef41Sopenharmony_ci  )
301cb0ef41Sopenharmony_ci  .end('asd')
311cb0ef41Sopenharmony_ci  .on('data', common.mustCall((buf) => {
321cb0ef41Sopenharmony_ci    res += buf;
331cb0ef41Sopenharmony_ci  }))
341cb0ef41Sopenharmony_ci  .on('end', common.mustCall(() => {
351cb0ef41Sopenharmony_ci    assert.strictEqual(res, 'ASDASD');
361cb0ef41Sopenharmony_ci  }));
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci{
401cb0ef41Sopenharmony_ci  let res = '';
411cb0ef41Sopenharmony_ci  compose(
421cb0ef41Sopenharmony_ci    async function*(source) {
431cb0ef41Sopenharmony_ci      for await (const chunk of source) {
441cb0ef41Sopenharmony_ci        yield chunk + chunk;
451cb0ef41Sopenharmony_ci      }
461cb0ef41Sopenharmony_ci    },
471cb0ef41Sopenharmony_ci    async function*(source) {
481cb0ef41Sopenharmony_ci      for await (const chunk of source) {
491cb0ef41Sopenharmony_ci        yield chunk.toString().toUpperCase();
501cb0ef41Sopenharmony_ci      }
511cb0ef41Sopenharmony_ci    }
521cb0ef41Sopenharmony_ci  )
531cb0ef41Sopenharmony_ci  .end('asd')
541cb0ef41Sopenharmony_ci  .on('data', common.mustCall((buf) => {
551cb0ef41Sopenharmony_ci    res += buf;
561cb0ef41Sopenharmony_ci  }))
571cb0ef41Sopenharmony_ci  .on('end', common.mustCall(() => {
581cb0ef41Sopenharmony_ci    assert.strictEqual(res, 'ASDASD');
591cb0ef41Sopenharmony_ci  }));
601cb0ef41Sopenharmony_ci}
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci{
631cb0ef41Sopenharmony_ci  let res = '';
641cb0ef41Sopenharmony_ci  compose(
651cb0ef41Sopenharmony_ci    async function*(source) {
661cb0ef41Sopenharmony_ci      for await (const chunk of source) {
671cb0ef41Sopenharmony_ci        yield chunk + chunk;
681cb0ef41Sopenharmony_ci      }
691cb0ef41Sopenharmony_ci    }
701cb0ef41Sopenharmony_ci  )
711cb0ef41Sopenharmony_ci  .end('asd')
721cb0ef41Sopenharmony_ci  .on('data', common.mustCall((buf) => {
731cb0ef41Sopenharmony_ci    res += buf;
741cb0ef41Sopenharmony_ci  }))
751cb0ef41Sopenharmony_ci  .on('end', common.mustCall(() => {
761cb0ef41Sopenharmony_ci    assert.strictEqual(res, 'asdasd');
771cb0ef41Sopenharmony_ci  }));
781cb0ef41Sopenharmony_ci}
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci{
811cb0ef41Sopenharmony_ci  let res = '';
821cb0ef41Sopenharmony_ci  compose(
831cb0ef41Sopenharmony_ci    Readable.from(['asd']),
841cb0ef41Sopenharmony_ci    new Transform({
851cb0ef41Sopenharmony_ci      transform: common.mustCall((chunk, encoding, callback) => {
861cb0ef41Sopenharmony_ci        callback(null, chunk.toString().toUpperCase());
871cb0ef41Sopenharmony_ci      })
881cb0ef41Sopenharmony_ci    })
891cb0ef41Sopenharmony_ci  )
901cb0ef41Sopenharmony_ci  .on('data', common.mustCall((buf) => {
911cb0ef41Sopenharmony_ci    res += buf;
921cb0ef41Sopenharmony_ci  }))
931cb0ef41Sopenharmony_ci  .on('end', common.mustCall(() => {
941cb0ef41Sopenharmony_ci    assert.strictEqual(res, 'ASD');
951cb0ef41Sopenharmony_ci  }));
961cb0ef41Sopenharmony_ci}
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ci{
991cb0ef41Sopenharmony_ci  let res = '';
1001cb0ef41Sopenharmony_ci  compose(
1011cb0ef41Sopenharmony_ci    async function* () {
1021cb0ef41Sopenharmony_ci      yield 'asd';
1031cb0ef41Sopenharmony_ci    }(),
1041cb0ef41Sopenharmony_ci    new Transform({
1051cb0ef41Sopenharmony_ci      transform: common.mustCall((chunk, encoding, callback) => {
1061cb0ef41Sopenharmony_ci        callback(null, chunk.toString().toUpperCase());
1071cb0ef41Sopenharmony_ci      })
1081cb0ef41Sopenharmony_ci    })
1091cb0ef41Sopenharmony_ci  )
1101cb0ef41Sopenharmony_ci  .on('data', common.mustCall((buf) => {
1111cb0ef41Sopenharmony_ci    res += buf;
1121cb0ef41Sopenharmony_ci  }))
1131cb0ef41Sopenharmony_ci  .on('end', common.mustCall(() => {
1141cb0ef41Sopenharmony_ci    assert.strictEqual(res, 'ASD');
1151cb0ef41Sopenharmony_ci  }));
1161cb0ef41Sopenharmony_ci}
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci{
1191cb0ef41Sopenharmony_ci  let res = '';
1201cb0ef41Sopenharmony_ci  compose(
1211cb0ef41Sopenharmony_ci    new Transform({
1221cb0ef41Sopenharmony_ci      transform: common.mustCall((chunk, encoding, callback) => {
1231cb0ef41Sopenharmony_ci        callback(null, chunk.toString().toUpperCase());
1241cb0ef41Sopenharmony_ci      })
1251cb0ef41Sopenharmony_ci    }),
1261cb0ef41Sopenharmony_ci    async function*(source) {
1271cb0ef41Sopenharmony_ci      for await (const chunk of source) {
1281cb0ef41Sopenharmony_ci        yield chunk;
1291cb0ef41Sopenharmony_ci      }
1301cb0ef41Sopenharmony_ci    },
1311cb0ef41Sopenharmony_ci    new Writable({
1321cb0ef41Sopenharmony_ci      write: common.mustCall((chunk, encoding, callback) => {
1331cb0ef41Sopenharmony_ci        res += chunk;
1341cb0ef41Sopenharmony_ci        callback(null);
1351cb0ef41Sopenharmony_ci      })
1361cb0ef41Sopenharmony_ci    })
1371cb0ef41Sopenharmony_ci  )
1381cb0ef41Sopenharmony_ci  .end('asd')
1391cb0ef41Sopenharmony_ci  .on('finish', common.mustCall(() => {
1401cb0ef41Sopenharmony_ci    assert.strictEqual(res, 'ASD');
1411cb0ef41Sopenharmony_ci  }));
1421cb0ef41Sopenharmony_ci}
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ci{
1451cb0ef41Sopenharmony_ci  let res = '';
1461cb0ef41Sopenharmony_ci  compose(
1471cb0ef41Sopenharmony_ci    new Transform({
1481cb0ef41Sopenharmony_ci      transform: common.mustCall((chunk, encoding, callback) => {
1491cb0ef41Sopenharmony_ci        callback(null, chunk.toString().toUpperCase());
1501cb0ef41Sopenharmony_ci      })
1511cb0ef41Sopenharmony_ci    }),
1521cb0ef41Sopenharmony_ci    async function*(source) {
1531cb0ef41Sopenharmony_ci      for await (const chunk of source) {
1541cb0ef41Sopenharmony_ci        yield chunk;
1551cb0ef41Sopenharmony_ci      }
1561cb0ef41Sopenharmony_ci    },
1571cb0ef41Sopenharmony_ci    async function(source) {
1581cb0ef41Sopenharmony_ci      for await (const chunk of source) {
1591cb0ef41Sopenharmony_ci        res += chunk;
1601cb0ef41Sopenharmony_ci      }
1611cb0ef41Sopenharmony_ci    }
1621cb0ef41Sopenharmony_ci  )
1631cb0ef41Sopenharmony_ci  .end('asd')
1641cb0ef41Sopenharmony_ci  .on('finish', common.mustCall(() => {
1651cb0ef41Sopenharmony_ci    assert.strictEqual(res, 'ASD');
1661cb0ef41Sopenharmony_ci  }));
1671cb0ef41Sopenharmony_ci}
1681cb0ef41Sopenharmony_ci
1691cb0ef41Sopenharmony_ci{
1701cb0ef41Sopenharmony_ci  let res;
1711cb0ef41Sopenharmony_ci  compose(
1721cb0ef41Sopenharmony_ci    new Transform({
1731cb0ef41Sopenharmony_ci      objectMode: true,
1741cb0ef41Sopenharmony_ci      transform: common.mustCall((chunk, encoding, callback) => {
1751cb0ef41Sopenharmony_ci        callback(null, { chunk });
1761cb0ef41Sopenharmony_ci      })
1771cb0ef41Sopenharmony_ci    }),
1781cb0ef41Sopenharmony_ci    async function*(source) {
1791cb0ef41Sopenharmony_ci      for await (const chunk of source) {
1801cb0ef41Sopenharmony_ci        yield chunk;
1811cb0ef41Sopenharmony_ci      }
1821cb0ef41Sopenharmony_ci    },
1831cb0ef41Sopenharmony_ci    new Transform({
1841cb0ef41Sopenharmony_ci      objectMode: true,
1851cb0ef41Sopenharmony_ci      transform: common.mustCall((chunk, encoding, callback) => {
1861cb0ef41Sopenharmony_ci        callback(null, { chunk });
1871cb0ef41Sopenharmony_ci      })
1881cb0ef41Sopenharmony_ci    })
1891cb0ef41Sopenharmony_ci  )
1901cb0ef41Sopenharmony_ci  .end(true)
1911cb0ef41Sopenharmony_ci  .on('data', common.mustCall((buf) => {
1921cb0ef41Sopenharmony_ci    res = buf;
1931cb0ef41Sopenharmony_ci  }))
1941cb0ef41Sopenharmony_ci  .on('end', common.mustCall(() => {
1951cb0ef41Sopenharmony_ci    assert.strictEqual(res.chunk.chunk, true);
1961cb0ef41Sopenharmony_ci  }));
1971cb0ef41Sopenharmony_ci}
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ci{
2001cb0ef41Sopenharmony_ci  const _err = new Error('asd');
2011cb0ef41Sopenharmony_ci  compose(
2021cb0ef41Sopenharmony_ci    new Transform({
2031cb0ef41Sopenharmony_ci      objectMode: true,
2041cb0ef41Sopenharmony_ci      transform: common.mustCall((chunk, encoding, callback) => {
2051cb0ef41Sopenharmony_ci        callback(_err);
2061cb0ef41Sopenharmony_ci      })
2071cb0ef41Sopenharmony_ci    }),
2081cb0ef41Sopenharmony_ci    async function*(source) {
2091cb0ef41Sopenharmony_ci      for await (const chunk of source) {
2101cb0ef41Sopenharmony_ci        yield chunk;
2111cb0ef41Sopenharmony_ci      }
2121cb0ef41Sopenharmony_ci    },
2131cb0ef41Sopenharmony_ci    new Transform({
2141cb0ef41Sopenharmony_ci      objectMode: true,
2151cb0ef41Sopenharmony_ci      transform: common.mustNotCall((chunk, encoding, callback) => {
2161cb0ef41Sopenharmony_ci        callback(null, { chunk });
2171cb0ef41Sopenharmony_ci      })
2181cb0ef41Sopenharmony_ci    })
2191cb0ef41Sopenharmony_ci  )
2201cb0ef41Sopenharmony_ci  .end(true)
2211cb0ef41Sopenharmony_ci  .on('data', common.mustNotCall())
2221cb0ef41Sopenharmony_ci  .on('end', common.mustNotCall())
2231cb0ef41Sopenharmony_ci  .on('error', (err) => {
2241cb0ef41Sopenharmony_ci    assert.strictEqual(err, _err);
2251cb0ef41Sopenharmony_ci  });
2261cb0ef41Sopenharmony_ci}
2271cb0ef41Sopenharmony_ci
2281cb0ef41Sopenharmony_ci{
2291cb0ef41Sopenharmony_ci  const _err = new Error('asd');
2301cb0ef41Sopenharmony_ci  compose(
2311cb0ef41Sopenharmony_ci    new Transform({
2321cb0ef41Sopenharmony_ci      objectMode: true,
2331cb0ef41Sopenharmony_ci      transform: common.mustCall((chunk, encoding, callback) => {
2341cb0ef41Sopenharmony_ci        callback(null, chunk);
2351cb0ef41Sopenharmony_ci      })
2361cb0ef41Sopenharmony_ci    }),
2371cb0ef41Sopenharmony_ci    async function*(source) { // eslint-disable-line require-yield
2381cb0ef41Sopenharmony_ci      let tmp = '';
2391cb0ef41Sopenharmony_ci      for await (const chunk of source) {
2401cb0ef41Sopenharmony_ci        tmp += chunk;
2411cb0ef41Sopenharmony_ci        throw _err;
2421cb0ef41Sopenharmony_ci      }
2431cb0ef41Sopenharmony_ci      return tmp;
2441cb0ef41Sopenharmony_ci    },
2451cb0ef41Sopenharmony_ci    new Transform({
2461cb0ef41Sopenharmony_ci      objectMode: true,
2471cb0ef41Sopenharmony_ci      transform: common.mustNotCall((chunk, encoding, callback) => {
2481cb0ef41Sopenharmony_ci        callback(null, { chunk });
2491cb0ef41Sopenharmony_ci      })
2501cb0ef41Sopenharmony_ci    })
2511cb0ef41Sopenharmony_ci  )
2521cb0ef41Sopenharmony_ci  .end(true)
2531cb0ef41Sopenharmony_ci  .on('data', common.mustNotCall())
2541cb0ef41Sopenharmony_ci  .on('end', common.mustNotCall())
2551cb0ef41Sopenharmony_ci  .on('error', (err) => {
2561cb0ef41Sopenharmony_ci    assert.strictEqual(err, _err);
2571cb0ef41Sopenharmony_ci  });
2581cb0ef41Sopenharmony_ci}
2591cb0ef41Sopenharmony_ci
2601cb0ef41Sopenharmony_ci{
2611cb0ef41Sopenharmony_ci  let buf = '';
2621cb0ef41Sopenharmony_ci
2631cb0ef41Sopenharmony_ci  // Convert into readable Duplex.
2641cb0ef41Sopenharmony_ci  const s1 = compose(async function* () {
2651cb0ef41Sopenharmony_ci    yield 'Hello';
2661cb0ef41Sopenharmony_ci    yield 'World';
2671cb0ef41Sopenharmony_ci  }(), async function* (source) {
2681cb0ef41Sopenharmony_ci    for await (const chunk of source) {
2691cb0ef41Sopenharmony_ci      yield String(chunk).toUpperCase();
2701cb0ef41Sopenharmony_ci    }
2711cb0ef41Sopenharmony_ci  }, async function(source) {
2721cb0ef41Sopenharmony_ci    for await (const chunk of source) {
2731cb0ef41Sopenharmony_ci      buf += chunk;
2741cb0ef41Sopenharmony_ci    }
2751cb0ef41Sopenharmony_ci  });
2761cb0ef41Sopenharmony_ci
2771cb0ef41Sopenharmony_ci  assert.strictEqual(s1.writable, false);
2781cb0ef41Sopenharmony_ci  assert.strictEqual(s1.readable, false);
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ci  finished(s1.resume(), common.mustCall((err) => {
2811cb0ef41Sopenharmony_ci    assert(!err);
2821cb0ef41Sopenharmony_ci    assert.strictEqual(buf, 'HELLOWORLD');
2831cb0ef41Sopenharmony_ci  }));
2841cb0ef41Sopenharmony_ci}
2851cb0ef41Sopenharmony_ci
2861cb0ef41Sopenharmony_ci{
2871cb0ef41Sopenharmony_ci  let buf = '';
2881cb0ef41Sopenharmony_ci  // Convert into transform duplex.
2891cb0ef41Sopenharmony_ci  const s2 = compose(async function* (source) {
2901cb0ef41Sopenharmony_ci    for await (const chunk of source) {
2911cb0ef41Sopenharmony_ci      yield String(chunk).toUpperCase();
2921cb0ef41Sopenharmony_ci    }
2931cb0ef41Sopenharmony_ci  });
2941cb0ef41Sopenharmony_ci  s2.end('helloworld');
2951cb0ef41Sopenharmony_ci  s2.resume();
2961cb0ef41Sopenharmony_ci  s2.on('data', (chunk) => {
2971cb0ef41Sopenharmony_ci    buf += chunk;
2981cb0ef41Sopenharmony_ci  });
2991cb0ef41Sopenharmony_ci
3001cb0ef41Sopenharmony_ci  finished(s2.resume(), common.mustCall((err) => {
3011cb0ef41Sopenharmony_ci    assert(!err);
3021cb0ef41Sopenharmony_ci    assert.strictEqual(buf, 'HELLOWORLD');
3031cb0ef41Sopenharmony_ci  }));
3041cb0ef41Sopenharmony_ci}
3051cb0ef41Sopenharmony_ci
3061cb0ef41Sopenharmony_ci{
3071cb0ef41Sopenharmony_ci  let buf = '';
3081cb0ef41Sopenharmony_ci
3091cb0ef41Sopenharmony_ci  // Convert into readable Duplex.
3101cb0ef41Sopenharmony_ci  const s1 = compose(async function* () {
3111cb0ef41Sopenharmony_ci    yield 'Hello';
3121cb0ef41Sopenharmony_ci    yield 'World';
3131cb0ef41Sopenharmony_ci  }());
3141cb0ef41Sopenharmony_ci
3151cb0ef41Sopenharmony_ci  // Convert into transform duplex.
3161cb0ef41Sopenharmony_ci  const s2 = compose(async function* (source) {
3171cb0ef41Sopenharmony_ci    for await (const chunk of source) {
3181cb0ef41Sopenharmony_ci      yield String(chunk).toUpperCase();
3191cb0ef41Sopenharmony_ci    }
3201cb0ef41Sopenharmony_ci  });
3211cb0ef41Sopenharmony_ci
3221cb0ef41Sopenharmony_ci  // Convert into writable duplex.
3231cb0ef41Sopenharmony_ci  const s3 = compose(async function(source) {
3241cb0ef41Sopenharmony_ci    for await (const chunk of source) {
3251cb0ef41Sopenharmony_ci      buf += chunk;
3261cb0ef41Sopenharmony_ci    }
3271cb0ef41Sopenharmony_ci  });
3281cb0ef41Sopenharmony_ci
3291cb0ef41Sopenharmony_ci  const s4 = compose(s1, s2, s3);
3301cb0ef41Sopenharmony_ci
3311cb0ef41Sopenharmony_ci  finished(s4, common.mustCall((err) => {
3321cb0ef41Sopenharmony_ci    assert(!err);
3331cb0ef41Sopenharmony_ci    assert.strictEqual(buf, 'HELLOWORLD');
3341cb0ef41Sopenharmony_ci  }));
3351cb0ef41Sopenharmony_ci}
3361cb0ef41Sopenharmony_ci
3371cb0ef41Sopenharmony_ci{
3381cb0ef41Sopenharmony_ci  let buf = '';
3391cb0ef41Sopenharmony_ci
3401cb0ef41Sopenharmony_ci  // Convert into readable Duplex.
3411cb0ef41Sopenharmony_ci  const s1 = compose(async function* () {
3421cb0ef41Sopenharmony_ci    yield 'Hello';
3431cb0ef41Sopenharmony_ci    yield 'World';
3441cb0ef41Sopenharmony_ci  }(), async function* (source) {
3451cb0ef41Sopenharmony_ci    for await (const chunk of source) {
3461cb0ef41Sopenharmony_ci      yield String(chunk).toUpperCase();
3471cb0ef41Sopenharmony_ci    }
3481cb0ef41Sopenharmony_ci  }, async function(source) {
3491cb0ef41Sopenharmony_ci    for await (const chunk of source) {
3501cb0ef41Sopenharmony_ci      buf += chunk;
3511cb0ef41Sopenharmony_ci    }
3521cb0ef41Sopenharmony_ci  });
3531cb0ef41Sopenharmony_ci
3541cb0ef41Sopenharmony_ci  finished(s1, common.mustCall((err) => {
3551cb0ef41Sopenharmony_ci    assert(!err);
3561cb0ef41Sopenharmony_ci    assert.strictEqual(buf, 'HELLOWORLD');
3571cb0ef41Sopenharmony_ci  }));
3581cb0ef41Sopenharmony_ci}
3591cb0ef41Sopenharmony_ci
3601cb0ef41Sopenharmony_ci{
3611cb0ef41Sopenharmony_ci  assert.throws(
3621cb0ef41Sopenharmony_ci    () => compose(),
3631cb0ef41Sopenharmony_ci    { code: 'ERR_MISSING_ARGS' }
3641cb0ef41Sopenharmony_ci  );
3651cb0ef41Sopenharmony_ci}
3661cb0ef41Sopenharmony_ci
3671cb0ef41Sopenharmony_ci{
3681cb0ef41Sopenharmony_ci  assert.throws(
3691cb0ef41Sopenharmony_ci    () => compose(new Writable(), new PassThrough()),
3701cb0ef41Sopenharmony_ci    { code: 'ERR_INVALID_ARG_VALUE' }
3711cb0ef41Sopenharmony_ci  );
3721cb0ef41Sopenharmony_ci}
3731cb0ef41Sopenharmony_ci
3741cb0ef41Sopenharmony_ci{
3751cb0ef41Sopenharmony_ci  assert.throws(
3761cb0ef41Sopenharmony_ci    () => compose(new PassThrough(), new Readable({ read() {} }), new PassThrough()),
3771cb0ef41Sopenharmony_ci    { code: 'ERR_INVALID_ARG_VALUE' }
3781cb0ef41Sopenharmony_ci  );
3791cb0ef41Sopenharmony_ci}
3801cb0ef41Sopenharmony_ci
3811cb0ef41Sopenharmony_ci{
3821cb0ef41Sopenharmony_ci  let buf = '';
3831cb0ef41Sopenharmony_ci
3841cb0ef41Sopenharmony_ci  // Convert into readable Duplex.
3851cb0ef41Sopenharmony_ci  const s1 = compose(async function* () {
3861cb0ef41Sopenharmony_ci    yield 'Hello';
3871cb0ef41Sopenharmony_ci    yield 'World';
3881cb0ef41Sopenharmony_ci  }(), async function* (source) {
3891cb0ef41Sopenharmony_ci    for await (const chunk of source) {
3901cb0ef41Sopenharmony_ci      yield String(chunk).toUpperCase();
3911cb0ef41Sopenharmony_ci    }
3921cb0ef41Sopenharmony_ci  }, async function(source) {
3931cb0ef41Sopenharmony_ci    for await (const chunk of source) {
3941cb0ef41Sopenharmony_ci      buf += chunk;
3951cb0ef41Sopenharmony_ci    }
3961cb0ef41Sopenharmony_ci    return buf;
3971cb0ef41Sopenharmony_ci  });
3981cb0ef41Sopenharmony_ci
3991cb0ef41Sopenharmony_ci  finished(s1, common.mustCall((err) => {
4001cb0ef41Sopenharmony_ci    assert.strictEqual(err.code, 'ERR_INVALID_RETURN_VALUE');
4011cb0ef41Sopenharmony_ci  }));
4021cb0ef41Sopenharmony_ci}
4031cb0ef41Sopenharmony_ci
4041cb0ef41Sopenharmony_ci{
4051cb0ef41Sopenharmony_ci  let buf = '';
4061cb0ef41Sopenharmony_ci
4071cb0ef41Sopenharmony_ci  // Convert into readable Duplex.
4081cb0ef41Sopenharmony_ci  const s1 = compose('HelloWorld', async function* (source) {
4091cb0ef41Sopenharmony_ci    for await (const chunk of source) {
4101cb0ef41Sopenharmony_ci      yield String(chunk).toUpperCase();
4111cb0ef41Sopenharmony_ci    }
4121cb0ef41Sopenharmony_ci  }, async function(source) {
4131cb0ef41Sopenharmony_ci    for await (const chunk of source) {
4141cb0ef41Sopenharmony_ci      buf += chunk;
4151cb0ef41Sopenharmony_ci    }
4161cb0ef41Sopenharmony_ci  });
4171cb0ef41Sopenharmony_ci
4181cb0ef41Sopenharmony_ci  finished(s1, common.mustCall((err) => {
4191cb0ef41Sopenharmony_ci    assert(!err);
4201cb0ef41Sopenharmony_ci    assert.strictEqual(buf, 'HELLOWORLD');
4211cb0ef41Sopenharmony_ci  }));
4221cb0ef41Sopenharmony_ci}
4231cb0ef41Sopenharmony_ci
4241cb0ef41Sopenharmony_ci{
4251cb0ef41Sopenharmony_ci  // In the new stream than should use the writeable of the first stream and readable of the last stream
4261cb0ef41Sopenharmony_ci  // #46829
4271cb0ef41Sopenharmony_ci  (async () => {
4281cb0ef41Sopenharmony_ci    const newStream = compose(
4291cb0ef41Sopenharmony_ci      new PassThrough({
4301cb0ef41Sopenharmony_ci        // reading FROM you in object mode or not
4311cb0ef41Sopenharmony_ci        readableObjectMode: false,
4321cb0ef41Sopenharmony_ci
4331cb0ef41Sopenharmony_ci        // writing TO you in object mode or not
4341cb0ef41Sopenharmony_ci        writableObjectMode: false,
4351cb0ef41Sopenharmony_ci      }),
4361cb0ef41Sopenharmony_ci      new Transform({
4371cb0ef41Sopenharmony_ci        // reading FROM you in object mode or not
4381cb0ef41Sopenharmony_ci        readableObjectMode: true,
4391cb0ef41Sopenharmony_ci
4401cb0ef41Sopenharmony_ci        // writing TO you in object mode or not
4411cb0ef41Sopenharmony_ci        writableObjectMode: false,
4421cb0ef41Sopenharmony_ci        transform: (chunk, encoding, callback) => {
4431cb0ef41Sopenharmony_ci          callback(null, {
4441cb0ef41Sopenharmony_ci            value: chunk.toString()
4451cb0ef41Sopenharmony_ci          });
4461cb0ef41Sopenharmony_ci        }
4471cb0ef41Sopenharmony_ci      })
4481cb0ef41Sopenharmony_ci    );
4491cb0ef41Sopenharmony_ci
4501cb0ef41Sopenharmony_ci    assert.strictEqual(newStream.writableObjectMode, false);
4511cb0ef41Sopenharmony_ci    assert.strictEqual(newStream.readableObjectMode, true);
4521cb0ef41Sopenharmony_ci
4531cb0ef41Sopenharmony_ci    newStream.write('Steve Rogers');
4541cb0ef41Sopenharmony_ci    newStream.write('On your left');
4551cb0ef41Sopenharmony_ci
4561cb0ef41Sopenharmony_ci    newStream.end();
4571cb0ef41Sopenharmony_ci
4581cb0ef41Sopenharmony_ci    assert.deepStrictEqual(await newStream.toArray(), [{ value: 'Steve Rogers' }, { value: 'On your left' }]);
4591cb0ef41Sopenharmony_ci  })().then(common.mustCall());
4601cb0ef41Sopenharmony_ci}
4611cb0ef41Sopenharmony_ci
4621cb0ef41Sopenharmony_ci{
4631cb0ef41Sopenharmony_ci  // In the new stream than should use the writeable of the first stream and readable of the last stream
4641cb0ef41Sopenharmony_ci  // #46829
4651cb0ef41Sopenharmony_ci  (async () => {
4661cb0ef41Sopenharmony_ci    const newStream = compose(
4671cb0ef41Sopenharmony_ci      new PassThrough({
4681cb0ef41Sopenharmony_ci        // reading FROM you in object mode or not
4691cb0ef41Sopenharmony_ci        readableObjectMode: true,
4701cb0ef41Sopenharmony_ci
4711cb0ef41Sopenharmony_ci        // writing TO you in object mode or not
4721cb0ef41Sopenharmony_ci        writableObjectMode: true,
4731cb0ef41Sopenharmony_ci      }),
4741cb0ef41Sopenharmony_ci      new Transform({
4751cb0ef41Sopenharmony_ci        // reading FROM you in object mode or not
4761cb0ef41Sopenharmony_ci        readableObjectMode: false,
4771cb0ef41Sopenharmony_ci
4781cb0ef41Sopenharmony_ci        // writing TO you in object mode or not
4791cb0ef41Sopenharmony_ci        writableObjectMode: true,
4801cb0ef41Sopenharmony_ci        transform: (chunk, encoding, callback) => {
4811cb0ef41Sopenharmony_ci          callback(null, chunk.value);
4821cb0ef41Sopenharmony_ci        }
4831cb0ef41Sopenharmony_ci      })
4841cb0ef41Sopenharmony_ci    );
4851cb0ef41Sopenharmony_ci
4861cb0ef41Sopenharmony_ci    assert.strictEqual(newStream.writableObjectMode, true);
4871cb0ef41Sopenharmony_ci    assert.strictEqual(newStream.readableObjectMode, false);
4881cb0ef41Sopenharmony_ci
4891cb0ef41Sopenharmony_ci    newStream.write({ value: 'Steve Rogers' });
4901cb0ef41Sopenharmony_ci    newStream.write({ value: 'On your left' });
4911cb0ef41Sopenharmony_ci
4921cb0ef41Sopenharmony_ci    newStream.end();
4931cb0ef41Sopenharmony_ci
4941cb0ef41Sopenharmony_ci    assert.deepStrictEqual(await newStream.toArray(), [Buffer.from('Steve RogersOn your left')]);
4951cb0ef41Sopenharmony_ci  })().then(common.mustCall());
4961cb0ef41Sopenharmony_ci}
497