11'use strict' ;
22require ( '../common' ) ;
33
4- // This test checks that the maxBuffer option for child_process.spawnSync ()
4+ // This test checks that the maxBuffer option for child_process.execFileSync ()
55// works as expected.
66
77const assert = require ( 'assert' ) ;
8- const execFileSync = require ( 'child_process' ) . execFileSync ;
8+ const { execFileSync } = require ( 'child_process' ) ;
99const msgOut = 'this is stdout' ;
1010const msgOutBuf = Buffer . from ( `${ msgOut } \n` ) ;
1111
@@ -16,15 +16,16 @@ const args = [
1616
1717// Verify that an error is returned if maxBuffer is surpassed.
1818{
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- assert . deepStrictEqual ( e . stdout , msgOutBuf ) ;
25- return true ;
26- }
27- ) ;
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+ } ) ;
2829}
2930
3031// Verify that a maxBuffer size of Infinity works.
@@ -34,19 +35,16 @@ const args = [
3435 assert . deepStrictEqual ( ret , msgOutBuf ) ;
3536}
3637
37- // maxBuffer size is 1024 * 1024 at default .
38+ // Default maxBuffer size is 1024 * 1024.
3839{
39- assert . throws (
40- ( ) => {
41- execFileSync (
42- process . execPath ,
43- [ '-e' , "console.log('a'.repeat(1024 * 1024))" ] ,
44- { encoding : 'utf-8' }
45- ) ;
46- } , ( e ) => {
47- assert . ok ( e , 'maxBuffer should error' ) ;
48- assert . strictEqual ( e . errno , 'ENOBUFS' ) ;
49- return true ;
50- }
51- ) ;
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+ } ) ;
5250}
0 commit comments