1'use strict'; 2require('../common'); 3 4// This test checks that the maxBuffer option for child_process.execFileSync() 5// works as expected. 6 7const assert = require('assert'); 8const { execFileSync } = require('child_process'); 9const msgOut = 'this is stdout'; 10const msgOutBuf = Buffer.from(`${msgOut}\n`); 11 12const args = [ 13 '-e', 14 `console.log("${msgOut}");` 15]; 16 17// Verify that an error is returned if maxBuffer is surpassed. 18{ 19 assert.throws(() => { 20 execFileSync(process.execPath, args, { maxBuffer: 1 }); 21 }, (e) => { 22 assert.ok(e, 'maxBuffer should error'); 23 assert.strictEqual(e.errno, 'ENOBUFS'); 24 // We can have buffers larger than maxBuffer because underneath we alloc 64k 25 // that matches our read sizes. 26 assert.deepStrictEqual(e.stdout, msgOutBuf); 27 return true; 28 }); 29} 30 31// Verify that a maxBuffer size of Infinity works. 32{ 33 const ret = execFileSync(process.execPath, args, { maxBuffer: Infinity }); 34 35 assert.deepStrictEqual(ret, msgOutBuf); 36} 37 38// Default maxBuffer size is 1024 * 1024. 39{ 40 assert.throws(() => { 41 execFileSync( 42 process.execPath, 43 ['-e', "console.log('a'.repeat(1024 * 1024))"] 44 ); 45 }, (e) => { 46 assert.ok(e, 'maxBuffer should error'); 47 assert.strictEqual(e.errno, 'ENOBUFS'); 48 return true; 49 }); 50} 51