Skip to content

Commit 86df27f

Browse files
committed
fixup! test only if crypto is present and an additional test from bug report
1 parent 8c60c33 commit 86df27f

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

test/parallel/test-blob.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,48 @@ assert.throws(() => new Blob({}), {
283283
})().then(common.mustCall());
284284

285285
(async () => {
286-
const file = new Blob(['<svg></svg>'], { type: 'image/svg+xml' });
287-
const url = URL.createObjectURL(file);
288-
const res = await fetch(url);
289-
const blob = await res.blob();
290-
assert.strictEqual(blob.size, 11);
291-
assert.strictEqual(blob.type, 'image/svg+xml');
292-
assert.strictEqual(await blob.text(), '<svg></svg>');
286+
const b = new Blob(['A', 'B', 'C']);
287+
const stream = b.stream();
288+
const chunks = [];
289+
const decoder = new TextDecoder();
290+
await stream.pipeTo(
291+
new WritableStream({
292+
write(chunk) {
293+
chunks.push(decoder.decode(chunk, { stream: true }));
294+
},
295+
})
296+
);
297+
assert.strictEqual(chunks.join(''), 'ABC');
298+
})().then(common.mustCall());
299+
300+
(async () => {
301+
// Ref: https://github.com/nodejs/node/issues/48668
302+
const chunks = [];
303+
const stream = new Blob(['Hello world']).stream();
304+
const decoder = new TextDecoder();
305+
await Promise.resolve();
306+
await stream.pipeTo(
307+
new WritableStream({
308+
write(chunk) {
309+
chunks.push(decoder.decode(chunk, { stream: true }));
310+
},
311+
})
312+
);
313+
assert.strictEqual(chunks.join(''), 'Hello world');
314+
})().then(common.mustCall());
315+
316+
(async () => {
317+
// Ref: https://github.com/nodejs/node/issues/48668
318+
if (common.hasCrypto) {
319+
// Can only do this test if we have node built with crypto
320+
const file = new Blob(['<svg></svg>'], { type: 'image/svg+xml' });
321+
const url = URL.createObjectURL(file);
322+
const res = await fetch(url);
323+
const blob = await res.blob();
324+
assert.strictEqual(blob.size, 11);
325+
assert.strictEqual(blob.type, 'image/svg+xml');
326+
assert.strictEqual(await blob.text(), '<svg></svg>');
327+
}
293328
})().then(common.mustCall());
294329

295330
(async () => {

0 commit comments

Comments
 (0)