Skip to content

Commit be44b1f

Browse files
kuriyoshtargos
authored andcommitted
test: improve test coverage of internal/blob
PR-URL: #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>
1 parent 2a07a9f commit be44b1f

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Flags: --no-warnings
2+
'use strict';
3+
4+
const common = require('../common');
5+
const assert = require('assert');
6+
const { Blob } = require('buffer');
7+
8+
if (common.isFreeBSD)
9+
common.skip('Oversized buffer make the FreeBSD CI runner crash');
10+
11+
try {
12+
new Blob([new Uint8Array(0xffffffff), [1]]);
13+
} catch (e) {
14+
if (
15+
e.message === 'Array buffer allocation failed' ||
16+
e.message === 'Invalid typed array length: 4294967295'
17+
) {
18+
common.skip(
19+
'Insufficient memory on this platform for oversized buffer test.'
20+
);
21+
} else {
22+
assert.strictEqual(e.code, 'ERR_BUFFER_TOO_LARGE');
23+
}
24+
}

test/parallel/test-blob.js

+26
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ assert.throws(() => new Blob({}), {
198198
const b = new Blob();
199199
assert.strictEqual(inspect(b, { depth: null }),
200200
'Blob { size: 0, type: \'\' }');
201+
assert.strictEqual(inspect(b, { depth: 1 }),
202+
'Blob { size: 0, type: \'\' }');
201203
assert.strictEqual(inspect(b, { depth: -1 }), '[Blob]');
202204
}
203205

@@ -230,6 +232,30 @@ assert.throws(() => new Blob({}), {
230232
});
231233
}
232234

235+
{
236+
assert.throws(() => Reflect.get(Blob.prototype, 'type', {}), {
237+
code: 'ERR_INVALID_THIS',
238+
});
239+
assert.throws(() => Reflect.get(Blob.prototype, 'size', {}), {
240+
code: 'ERR_INVALID_THIS',
241+
});
242+
assert.throws(() => Blob.prototype.slice(Blob.prototype, 0, 1), {
243+
code: 'ERR_INVALID_THIS',
244+
});
245+
assert.throws(() => Blob.prototype.stream.call(), {
246+
code: 'ERR_INVALID_THIS',
247+
});
248+
}
249+
250+
(async () => {
251+
assert.rejects(async () => Blob.prototype.arrayBuffer.call(), {
252+
code: 'ERR_INVALID_THIS',
253+
});
254+
assert.rejects(async () => Blob.prototype.text.call(), {
255+
code: 'ERR_INVALID_THIS',
256+
});
257+
})().then(common.mustCall());
258+
233259
(async () => {
234260
const blob = new Blob([
235261
new Uint8Array([0x50, 0x41, 0x53, 0x53]),

0 commit comments

Comments
 (0)