summaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-execfile-maxbuf.js
diff options
context:
space:
mode:
authorkohta ito <kohta110@gmail.com>2018-09-17 18:19:26 +0900
committerSam Roberts <vieuxtech@gmail.com>2019-04-03 18:32:26 -0700
commitceb80f415798818a059051537132bba691c68db7 (patch)
treef384a1a5319edeeb0801db266797be97bfdf06f3 /test/parallel/test-child-process-execfile-maxbuf.js
parentb180a1572768a16d14c08d1f847e2b8aa7afe87c (diff)
downloadandroid-node-v8-ceb80f415798818a059051537132bba691c68db7.tar.gz
android-node-v8-ceb80f415798818a059051537132bba691c68db7.tar.bz2
android-node-v8-ceb80f415798818a059051537132bba691c68db7.zip
doc: fix default maxBuffer size
Correctly document the default maxBuffer size for execSync, execFileSync, and spawnSync. It is 200 * 1024, not Infinity. Add tests to verify behaviour is as documented. PR-URL: https://github.com/nodejs/node/pull/22894 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Diffstat (limited to 'test/parallel/test-child-process-execfile-maxbuf.js')
-rw-r--r--test/parallel/test-child-process-execfile-maxbuf.js94
1 files changed, 94 insertions, 0 deletions
diff --git a/test/parallel/test-child-process-execfile-maxbuf.js b/test/parallel/test-child-process-execfile-maxbuf.js
new file mode 100644
index 0000000000..ba074630a1
--- /dev/null
+++ b/test/parallel/test-child-process-execfile-maxbuf.js
@@ -0,0 +1,94 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const { execFile } = require('child_process');
+
+function checkFactory(streamName) {
+ return common.mustCall((err) => {
+ assert(err instanceof RangeError);
+ assert.strictEqual(err.message, `${streamName} maxBuffer length exceeded`);
+ assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
+ });
+}
+
+// default value
+{
+ execFile(
+ process.execPath,
+ ['-e', 'console.log("a".repeat(200 * 1024))'],
+ checkFactory('stdout')
+ );
+}
+
+// default value
+{
+ execFile(
+ process.execPath,
+ ['-e', 'console.log("a".repeat(200 * 1024 - 1))'],
+ common.mustCall((err, stdout, stderr) => {
+ assert.ifError(err);
+ assert.strictEqual(stdout.trim(), 'a'.repeat(200 * 1024 - 1));
+ assert.strictEqual(stderr, '');
+ })
+ );
+}
+
+{
+ const options = { maxBuffer: Infinity };
+
+ execFile(
+ process.execPath,
+ ['-e', 'console.log("hello world");'],
+ options,
+ common.mustCall((err, stdout, stderr) => {
+ assert.ifError(err);
+ assert.strictEqual(stdout.trim(), 'hello world');
+ assert.strictEqual(stderr, '');
+ })
+ );
+}
+
+{
+ execFile('echo', ['hello world'], { maxBuffer: 5 }, checkFactory('stdout'));
+}
+
+const unicode = '中文测试'; // length = 4, byte length = 12
+
+{
+ execFile(
+ process.execPath,
+ ['-e', `console.log('${unicode}');`],
+ { maxBuffer: 10 },
+ checkFactory('stdout'));
+}
+
+{
+ execFile(
+ process.execPath,
+ ['-e', `console.error('${unicode}');`],
+ { maxBuffer: 10 },
+ checkFactory('stderr')
+ );
+}
+
+{
+ const child = execFile(
+ process.execPath,
+ ['-e', `console.log('${unicode}');`],
+ { encoding: null, maxBuffer: 10 },
+ checkFactory('stdout')
+ );
+
+ child.stdout.setEncoding('utf-8');
+}
+
+{
+ const child = execFile(
+ process.execPath,
+ ['-e', `console.error('${unicode}');`],
+ { encoding: null, maxBuffer: 10 },
+ checkFactory('stderr')
+ );
+
+ child.stderr.setEncoding('utf-8');
+}