Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYoshiki Kurihara <yosyos0306@gmail.com>2022-04-15 01:19:57 +0300
committerGitHub <noreply@github.com>2022-04-15 01:19:57 +0300
commit1285ac116d4334d1be3ce324591d28ec27bd61b2 (patch)
tree84d54e5b03b5b2bb997e55572dd96a3f739e1b2e /test
parent76e7170a40caf90b49827d156f37e0f3fe56fb2e (diff)
test: improve test coverage of internal/blob
PR-URL: https://github.com/nodejs/node/pull/41513 Refs: https://coverage.nodejs.org/coverage-74b9baa4265a8f0d/lib/internal/blob.js.html Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-blob-buffer-too-large.js24
-rw-r--r--test/parallel/test-blob.js26
2 files changed, 50 insertions, 0 deletions
diff --git a/test/parallel/test-blob-buffer-too-large.js b/test/parallel/test-blob-buffer-too-large.js
new file mode 100644
index 00000000000..2fd8b8754bd
--- /dev/null
+++ b/test/parallel/test-blob-buffer-too-large.js
@@ -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');
+ }
+}
diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js
index 53b9ddb0cb3..fe66ff08f94 100644
--- a/test/parallel/test-blob.js
+++ b/test/parallel/test-blob.js
@@ -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]');
}
@@ -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]),