node/test/parallel/test-child-process-spawnsync-maxbuf.js
cjihrig 5b30c4f24d test: refactor test-child-process-spawnsync-maxbuf
This commit refactors test-child-process-spawnsync-maxbuf.js,
and adds testing for the case where maxBuffer is Infinity.

PR-URL: https://github.com/nodejs/node/pull/10769
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-01-17 10:49:12 -05:00

33 lines
900 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const spawnSync = require('child_process').spawnSync;
const msgOut = 'this is stdout';
// This is actually not os.EOL?
const msgOutBuf = Buffer.from(msgOut + '\n');
const args = [
'-e',
`console.log("${msgOut}");`
];
// Verify that an error is returned if maxBuffer is surpassed.
{
const ret = spawnSync(process.execPath, args, { maxBuffer: 1 });
assert.ok(ret.error, 'maxBuffer should error');
assert.strictEqual(ret.error.errno, 'ENOBUFS');
// We can have buffers larger than maxBuffer because underneath we alloc 64k
// that matches our read sizes.
assert.deepStrictEqual(ret.stdout, msgOutBuf);
}
// Verify that a maxBuffer size of Infinity works.
{
const ret = spawnSync(process.execPath, args, { maxBuffer: Infinity });
assert.ifError(ret.error);
assert.deepStrictEqual(ret.stdout, msgOutBuf);
}