Skip to content

Commit 2105f15

Browse files
committed
test: deflake test-buffer-large-size
1 parent 77f88b9 commit 2105f15

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

test/pummel/test-buffer-large-size.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@ const stringTooLongError = {
2222
const size = 2 ** 31;
2323

2424
// Test Buffer.toString
25-
test('Buffer.toString with too long size', () => {
26-
try {
27-
assert.throws(() => SlowBuffer(size).toString('utf8'), stringTooLongError);
28-
assert.throws(() => Buffer.alloc(size).toString('utf8'), stringTooLongError);
29-
assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), stringTooLongError);
30-
assert.throws(() => Buffer.allocUnsafeSlow(size).toString('utf8'), stringTooLongError);
31-
} catch (e) {
32-
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
33-
throw e;
25+
const bufferMethodsToTest = [SlowBuffer, Buffer.alloc, Buffer.allocUnsafe, Buffer.allocUnsafeSlow];
26+
27+
bufferMethodsToTest.forEach((method) => {
28+
test(`${method.name} with too long size`, () => {
29+
try {
30+
assert.throws(() => method(size).toString('utf8'), stringTooLongError);
31+
} catch (e) {
32+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
33+
throw e;
34+
}
35+
common.skip('insufficient space for Buffer.alloc');
3436
}
35-
common.skip('insufficient space for Buffer.alloc');
36-
}
37+
});
3738
});
3839

3940
// Test Buffer.write

0 commit comments

Comments
 (0)