Skip to content

Commit 6de7441

Browse files
test: add adapter WritableStream ArrayBuffer and objectMode coverage
1 parent d791f39 commit 6de7441

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/parallel/test-whatwg-webstreams-adapters-to-writablestream.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,35 @@ class TestWritable extends Writable {
165165
const writer = writableStream.getWriter();
166166
writer.closed.then(common.mustCall());
167167
}
168+
169+
{
170+
const duplex = new PassThrough();
171+
const writableStream = newWritableStreamFromStreamWritable(duplex);
172+
const ec = new TextEncoder();
173+
const arrayBuffer = ec.encode('hello').buffer;
174+
writableStream
175+
.getWriter()
176+
.write(arrayBuffer)
177+
.then(common.mustCall());
178+
179+
duplex.on('data', common.mustCall((chunk) => {
180+
assert(chunk instanceof Buffer);
181+
assert(chunk.equals(Buffer.from('hello')));
182+
}));
183+
}
184+
185+
{
186+
const duplex = new PassThrough({ objectMode: true });
187+
const writableStream = newWritableStreamFromStreamWritable(duplex);
188+
const ec = new TextEncoder();
189+
const arrayBuffer = ec.encode('hello').buffer;
190+
writableStream
191+
.getWriter()
192+
.write(arrayBuffer)
193+
.then(common.mustCall());
194+
195+
duplex.on('data', common.mustCall((chunk) => {
196+
assert(chunk instanceof ArrayBuffer);
197+
assert.strictEqual(chunk, arrayBuffer);
198+
}));
199+
}

0 commit comments

Comments
 (0)