Skip to content

Commit

Permalink
test: improve test coverage of internal/blob
Browse files Browse the repository at this point in the history
PR-URL: nodejs#41513
Refs: https://coverage.nodejs.org/coverage-74b9baa4265a8f0d/lib/internal/blob.js.html
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
  • Loading branch information
kuriyosh authored and xtx1130 committed Apr 25, 2022
1 parent 00d6c76 commit 4d46c25
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/parallel/test-blob-buffer-too-large.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Flags: --no-warnings
'use strict';

const common = require('../common');
const assert = require('assert');
const { Blob } = require('buffer');

if (common.isFreeBSD)
common.skip('Oversized buffer make the FreeBSD CI runner crash');

try {
new Blob([new Uint8Array(0xffffffff), [1]]);
} catch (e) {
if (
e.message === 'Array buffer allocation failed' ||
e.message === 'Invalid typed array length: 4294967295'
) {
common.skip(
'Insufficient memory on this platform for oversized buffer test.'
);
} else {
assert.strictEqual(e.code, 'ERR_BUFFER_TOO_LARGE');
}
}
26 changes: 26 additions & 0 deletions test/parallel/test-blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ assert.throws(() => new Blob({}), {
const b = new Blob();
assert.strictEqual(inspect(b, { depth: null }),
'Blob { size: 0, type: \'\' }');
assert.strictEqual(inspect(b, { depth: 1 }),
'Blob { size: 0, type: \'\' }');
assert.strictEqual(inspect(b, { depth: -1 }), '[Blob]');
}

Expand Down Expand Up @@ -230,6 +232,30 @@ assert.throws(() => new Blob({}), {
});
}

{
assert.throws(() => Reflect.get(Blob.prototype, 'type', {}), {
code: 'ERR_INVALID_THIS',
});
assert.throws(() => Reflect.get(Blob.prototype, 'size', {}), {
code: 'ERR_INVALID_THIS',
});
assert.throws(() => Blob.prototype.slice(Blob.prototype, 0, 1), {
code: 'ERR_INVALID_THIS',
});
assert.throws(() => Blob.prototype.stream.call(), {
code: 'ERR_INVALID_THIS',
});
}

(async () => {
assert.rejects(async () => Blob.prototype.arrayBuffer.call(), {
code: 'ERR_INVALID_THIS',
});
assert.rejects(async () => Blob.prototype.text.call(), {
code: 'ERR_INVALID_THIS',
});
})().then(common.mustCall());

(async () => {
const blob = new Blob([
new Uint8Array([0x50, 0x41, 0x53, 0x53]),
Expand Down

0 comments on commit 4d46c25

Please sign in to comment.