diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index fdd4d239edc1f5..a517bad1ccb42d 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -283,13 +283,48 @@ assert.throws(() => new Blob({}), { })().then(common.mustCall()); (async () => { - const file = new Blob([''], { type: 'image/svg+xml' }); - const url = URL.createObjectURL(file); - const res = await fetch(url); - const blob = await res.blob(); - assert.strictEqual(blob.size, 11); - assert.strictEqual(blob.type, 'image/svg+xml'); - assert.strictEqual(await blob.text(), ''); + const b = new Blob(['A', 'B', 'C']); + const stream = b.stream(); + const chunks = []; + const decoder = new TextDecoder(); + await stream.pipeTo( + new WritableStream({ + write(chunk) { + chunks.push(decoder.decode(chunk, { stream: true })); + }, + }) + ); + assert.strictEqual(chunks.join(''), 'ABC'); +})().then(common.mustCall()); + +(async () => { + // Ref: https://github.com/nodejs/node/issues/48668 + const chunks = []; + const stream = new Blob(['Hello world']).stream(); + const decoder = new TextDecoder(); + await Promise.resolve(); + await stream.pipeTo( + new WritableStream({ + write(chunk) { + chunks.push(decoder.decode(chunk, { stream: true })); + }, + }) + ); + assert.strictEqual(chunks.join(''), 'Hello world'); +})().then(common.mustCall()); + +(async () => { + // Ref: https://github.com/nodejs/node/issues/48668 + if (common.hasCrypto) { + // Can only do this test if we have node built with crypto + const file = new Blob([''], { type: 'image/svg+xml' }); + const url = URL.createObjectURL(file); + const res = await fetch(url); + const blob = await res.blob(); + assert.strictEqual(blob.size, 11); + assert.strictEqual(blob.type, 'image/svg+xml'); + assert.strictEqual(await blob.text(), ''); + } })().then(common.mustCall()); (async () => {