node/test/parallel/test-buffer-tostring-rangeerror.js
Ruben Bridgewater 5f252a45bc
test: skip test-buffer-tostring-rangeerror when low on memory
This has shown up as RangeError: Array buffer allocation failed and
it should be totally fine to skip this test in case the memory is low.

PR-URL: https://github.com/nodejs/node/pull/58142
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-05-07 16:28:20 +00:00

30 lines
884 B
JavaScript

'use strict';
const common = require('../common');
// This test ensures that Node.js throws an Error when trying to convert a
// large buffer into a string.
// Regression test for https://github.com/nodejs/node/issues/649.
if (!common.enoughTestMem) {
common.skip('skipped due to memory requirements');
}
const assert = require('assert');
const {
Buffer,
constants: {
MAX_STRING_LENGTH,
},
} = require('buffer');
const len = MAX_STRING_LENGTH + 1;
const message = {
code: 'ERR_STRING_TOO_LONG',
name: 'Error',
};
assert.throws(() => Buffer(len).toString('utf8'), message);
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message);
assert.throws(() => Buffer.alloc(len).toString('utf8'), message);
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), message);
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message);