Skip to content

Commit

Permalink
fixup! test only if crypto is present and an additional test from bug…
Browse files Browse the repository at this point in the history
… report
  • Loading branch information
debadree25 committed Aug 11, 2023
1 parent 8c60c33 commit 86df27f
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions test/parallel/test-blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,48 @@ assert.throws(() => new Blob({}), {
})().then(common.mustCall());

(async () => {
const file = new Blob(['<svg></svg>'], { 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(), '<svg></svg>');
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(['<svg></svg>'], { 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(), '<svg></svg>');
}
})().then(common.mustCall());

(async () => {
Expand Down

0 comments on commit 86df27f

Please sign in to comment.