MCPcopy Index your code
hub / github.com/nodejs/node / tests

Function tests

test/parallel/test-stream-readable-async-iterators.js:15–649  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13const fs = require('fs');
14
15async function tests() {
16 {
17 // v1 stream
18
19 const stream = new Stream();
20 stream.destroy = common.mustCall();
21 process.nextTick(() => {
22 stream.emit('data', 'hello');
23 stream.emit('data', 'world');
24 stream.emit('end');
25 });
26
27 let res = '';
28 stream[Symbol.asyncIterator] = Readable.prototype[Symbol.asyncIterator];
29 for await (const d of stream) {
30 res += d;
31 }
32 assert.strictEqual(res, 'helloworld');
33 }
34
35 {
36 // v1 stream error
37
38 const stream = new Stream();
39 stream.close = common.mustCall();
40 process.nextTick(() => {
41 stream.emit('data', 0);
42 stream.emit('data', 1);
43 stream.emit('error', new Error('asd'));
44 });
45
46 const iter = Readable.prototype[Symbol.asyncIterator].call(stream);
47 await iter.next()
48 .then(common.mustNotCall())
49 .catch(common.mustCall((err) => {
50 assert.strictEqual(err.message, 'asd');
51 }));
52 }
53
54 {
55 // Non standard stream cleanup
56
57 const readable = new Readable({ autoDestroy: false, read() {} });
58 readable.push('asd');
59 readable.push('asd');
60 readable.destroy = null;
61 readable.close = common.mustCall(() => {
62 readable.emit('close');
63 });
64
65 await (async () => {
66 for await (const d of readable) {
67 return;
68 }
69 })();
70 }
71
72 {

Calls 15

allMethod · 0.80
cbFunction · 0.70
nextMethod · 0.65
forEachMethod · 0.65
sliceMethod · 0.65
pauseMethod · 0.65
pipelineFunction · 0.50
emitMethod · 0.45
callMethod · 0.45
thenMethod · 0.45
pushMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…