node/test/parallel/test-child-process-exec-maxBuffer.js
Jon Moss b1e6c0d44c errors, child_process: use internal/errors codes
PR-URL: https://github.com/nodejs/node/pull/14998
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
2017-11-29 18:14:27 -05:00

44 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
function checkFactory(streamName) {
return common.mustCall((err) => {
assert.strictEqual(err.message, `${streamName} maxBuffer length exceeded`);
assert(err instanceof RangeError);
assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
});
}
{
const cmd = `"${process.execPath}" -e "console.log('hello world');"`;
const options = { maxBuffer: Infinity };
cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
assert.strictEqual(stdout.trim(), 'hello world');
assert.strictEqual(stderr, '');
}));
}
{
const cmd = 'echo "hello world"';
cp.exec(cmd, { maxBuffer: 5 }, checkFactory('stdout'));
}
const unicode = '中文测试'; // length = 4, byte length = 12
{
const cmd = `"${process.execPath}" -e "console.log('${unicode}');"`;
cp.exec(cmd, { maxBuffer: 10 }, checkFactory('stdout'));
}
{
const cmd = `"${process.execPath}" -e "console.error('${unicode}');"`;
cp.exec(cmd, { maxBuffer: 10 }, checkFactory('stderr'));
}