Skip to content

Commit 0b62370

Browse files
joyeecheungMylesBorins
authored andcommitted
test: fix test for buffer regression #649
pass a regexp to assert.throws() PR-URL: #9924 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 11a098e commit 0b62370

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

test/parallel/test-buffer-regression-649.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ const SlowBuffer = require('buffer').SlowBuffer;
66

77
// Regression test for https://github.com/nodejs/node/issues/649.
88
const len = 1422561062959;
9-
assert.throws(() => Buffer(len).toString('utf8'));
10-
assert.throws(() => SlowBuffer(len).toString('utf8'));
11-
assert.throws(() => Buffer.alloc(len).toString('utf8'));
12-
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'));
13-
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'));
9+
const lenLimitMsg = new RegExp('^RangeError: (Invalid typed array length' +
10+
'|Array buffer allocation failed' +
11+
'|Invalid array buffer length)$');
12+
13+
assert.throws(() => Buffer(len).toString('utf8'), lenLimitMsg);
14+
assert.throws(() => SlowBuffer(len).toString('utf8'), lenLimitMsg);
15+
assert.throws(() => Buffer.alloc(len).toString('utf8'), lenLimitMsg);
16+
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), lenLimitMsg);
17+
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'),
18+
lenLimitMsg);

0 commit comments

Comments
 (0)