diff options
author | Refael Ackermann <refack@gmail.com> | 2018-08-25 12:23:53 -0400 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2018-08-29 17:32:13 -0400 |
commit | 8569f4a4178d1a114a95aabcb27cb30cb265e621 (patch) | |
tree | 7593ce9d3e386b79f5e64f800211b90ffa977fee /test/parallel/test-child-process-stdio.js | |
parent | 6a689c8aa3ef3bf517cc86807406b9a8958d4ffb (diff) | |
download | android-node-v8-8569f4a4178d1a114a95aabcb27cb30cb265e621.tar.gz android-node-v8-8569f4a4178d1a114a95aabcb27cb30cb265e621.tar.bz2 android-node-v8-8569f4a4178d1a114a95aabcb27cb30cb265e621.zip |
test: refacor spawn[Sync]Pwd
* extract the gist into common.pwdCommand
* Merge test-child-process-buffering.js into test-child-process-stdio.js
PR-URL: https://github.com/nodejs/node/pull/22522
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/parallel/test-child-process-stdio.js')
-rw-r--r-- | test/parallel/test-child-process-stdio.js | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/test/parallel/test-child-process-stdio.js b/test/parallel/test-child-process-stdio.js index 8624a13e1b..5ca3875f56 100644 --- a/test/parallel/test-child-process-stdio.js +++ b/test/parallel/test-child-process-stdio.js @@ -22,24 +22,56 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); -const spawnSync = require('child_process').spawnSync; +const { spawn } = require('child_process'); -let options = { stdio: ['pipe'] }; -let child = common.spawnPwd(options); +// Test stdio piping. +{ + const child = spawn(...common.pwdCommand, { stdio: ['pipe'] }); + assert.notStrictEqual(child.stdout, null); + assert.notStrictEqual(child.stderr, null); +} -assert.notStrictEqual(child.stdout, null); -assert.notStrictEqual(child.stderr, null); +// Test stdio ignoring. +{ + const child = spawn(...common.pwdCommand, { stdio: 'ignore' }); + assert.strictEqual(child.stdout, null); + assert.strictEqual(child.stderr, null); +} -options = { stdio: 'ignore' }; -child = common.spawnPwd(options); +// Asset options invariance. +{ + const options = { stdio: 'ignore' }; + spawn(...common.pwdCommand, options); + assert.deepStrictEqual(options, { stdio: 'ignore' }); +} -assert.strictEqual(child.stdout, null); -assert.strictEqual(child.stderr, null); +// Test stdout buffering. +{ + let output = ''; + const child = spawn(...common.pwdCommand); -options = { stdio: 'ignore' }; -child = spawnSync('cat', [], options); -assert.deepStrictEqual(options, { stdio: 'ignore' }); + child.stdout.setEncoding('utf8'); + child.stdout.on('data', function(s) { + output += s; + }); -common.expectsError(() => { - common.spawnPwd({ stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'ipc'] }); -}, { code: 'ERR_IPC_ONE_PIPE', type: Error }); + child.on('exit', common.mustCall(function(code) { + assert.strictEqual(code, 0); + })); + + child.on('close', common.mustCall(function() { + assert.strictEqual(true, output.length > 1); + assert.strictEqual('\n', output[output.length - 1]); + })); +} + +// Assert only one IPC pipe allowed. +common.expectsError( + () => { + spawn( + ...common.pwdCommand, + { stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'ipc'] } + ); + }, + { code: 'ERR_IPC_ONE_PIPE', type: Error } +); |