1
1
'use strict' ;
2
2
require ( '../common' ) ;
3
3
4
- // This test checks that the maxBuffer option for child_process.spawnSync ()
4
+ // This test checks that the maxBuffer option for child_process.execFileSync ()
5
5
// works as expected.
6
6
7
7
const assert = require ( 'assert' ) ;
8
- const execFileSync = require ( 'child_process' ) . execFileSync ;
8
+ const { execFileSync } = require ( 'child_process' ) ;
9
9
const msgOut = 'this is stdout' ;
10
10
const msgOutBuf = Buffer . from ( `${ msgOut } \n` ) ;
11
11
@@ -16,15 +16,16 @@ const args = [
16
16
17
17
// Verify that an error is returned if maxBuffer is surpassed.
18
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
- 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
+ } ) ;
28
29
}
29
30
30
31
// Verify that a maxBuffer size of Infinity works.
@@ -34,19 +35,16 @@ const args = [
34
35
assert . deepStrictEqual ( ret , msgOutBuf ) ;
35
36
}
36
37
37
- // maxBuffer size is 1024 * 1024 at default .
38
+ // Default maxBuffer size is 1024 * 1024.
38
39
{
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
+ } ) ;
52
50
}
0 commit comments