From dd4586bd4127a346d0175ed4b2050558b57184a1 Mon Sep 17 00:00:00 2001 From: joyeecheung Date: Thu, 1 Dec 2016 10:33:24 -0600 Subject: [PATCH] test: fix test for buffer regression #649 pass a regexp to assert.throws() PR-URL: https://github.com/nodejs/node/pull/9924 Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- test/parallel/test-buffer-regression-649.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-buffer-regression-649.js b/test/parallel/test-buffer-regression-649.js index b11e4a50e5d447..ab7228e84c1c13 100644 --- a/test/parallel/test-buffer-regression-649.js +++ b/test/parallel/test-buffer-regression-649.js @@ -6,8 +6,13 @@ const SlowBuffer = require('buffer').SlowBuffer; // Regression test for https://github.com/nodejs/node/issues/649. const len = 1422561062959; -assert.throws(() => Buffer(len).toString('utf8')); -assert.throws(() => SlowBuffer(len).toString('utf8')); -assert.throws(() => Buffer.alloc(len).toString('utf8')); -assert.throws(() => Buffer.allocUnsafe(len).toString('utf8')); -assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8')); +const lenLimitMsg = new RegExp('^RangeError: (Invalid typed array length' + + '|Array buffer allocation failed' + + '|Invalid array buffer length)$'); + +assert.throws(() => Buffer(len).toString('utf8'), lenLimitMsg); +assert.throws(() => SlowBuffer(len).toString('utf8'), lenLimitMsg); +assert.throws(() => Buffer.alloc(len).toString('utf8'), lenLimitMsg); +assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), lenLimitMsg); +assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), + lenLimitMsg);