Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Commit

Permalink
Process stdin should be 'inherit' by defualt
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroaki-yamamoto committed Jan 7, 2017
1 parent d369b6e commit 5eecd62
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
6 changes: 5 additions & 1 deletion lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
module.exports = (command, args, opt) => {
const childProcess = require('child_process');
const merge = require('merge');
const finalOpt = merge({'shell': true}, opt);
const defaultOptions = {
'shell': true,
'stdio': [process.stdin, 'pipe', 'pipe'],
};
const finalOpt = merge(defaultOptions, opt);
return new Promise((res, rej) => {
const proc = childProcess.spawn(
[].concat(command).join('&&'), args, finalOpt
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-process",
"version": "1.0.8",
"version": "1.0.9",
"description": "Child process that uses Promise Object",
"main": "index.js",
"scripts": {
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_pyvenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
});
it('Should call processCall with proper args.', () => {
expect(promiseProcessMock.calledOnce).to.be.true;
expect(promiseProcessMock.getCall(0).args[0]).to.eql([
expect(promiseProcessMock.getCall(0).args).to.eql([[
`. ${path.join(process.cwd(), 'venv', 'bin', 'activate')}`,
testCommand, 'deactivate',
]);
]]);
});
it('The return value should be an instance of promise', () => {
expect(ret).to.eql({});
Expand All @@ -56,10 +56,10 @@
});
it('Should call processCall with proper args.', () => {
expect(promiseProcessMock.calledOnce).to.be.true;
expect(promiseProcessMock.getCall(0).args[0]).to.eql([].concat(
expect(promiseProcessMock.getCall(0).args).to.eql([[].concat(
`. ${path.join(process.cwd(), 'venv', 'bin', 'activate')}`,
testCommand, 'deactivate'
));
)]);
});
it('The return value should be an instance of promise', () => {
expect(ret).to.eql({});
Expand All @@ -78,10 +78,10 @@
});
it('Should call processCall with proper args.', () => {
expect(promiseProcessMock.calledOnce).to.be.true;
expect(promiseProcessMock.getCall(0).args[0]).to.eql([
expect(promiseProcessMock.getCall(0).args).to.eql([[
`. ${path.join('test', 'bin', 'activate')}`,
testCommand, 'deactivate',
]);
]]);
});
it('The return value should be an instance of promise', () => {
expect(ret).to.eql({});
Expand All @@ -100,10 +100,10 @@
});
it('Should call processCall with proper args.', () => {
expect(promiseProcessMock.calledOnce).to.be.true;
expect(promiseProcessMock.getCall(0).args[0]).to.eql([
expect(promiseProcessMock.getCall(0).args).to.eql([[
`. ${path.join('test', 'bin', 'activate')}`,
testCommand, 'deactivate',
]);
]]);
});
it('The return value should be an instance of promise', () => {
expect(ret).to.eql({});
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/test_spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
expect(spawn.callCount).to.equal(1);
expect(spawn.calledWithExactly(expectedCommand, undefined, {
'shell': true,
'stdio': [process.stdin, 'pipe', 'pipe'],
})).is.true;
});
it('Should assign stdout data event', () => {
Expand All @@ -72,12 +73,14 @@
const testCommand = 'jugemjugemgokohnosurikire';
const testArgs = ['--kayjare=\'suygyo\'', '--soygyo=\'matsu\''];
beforeEach(() => {
promiseProcess(testCommand, testArgs, {'shell': false});
promiseProcess(
testCommand, testArgs, {'shell': false, 'stdio': 'pipe'}
);
});
it('Should call spawn with the command', () => {
expect(spawn.callCount).to.equal(1);
expect(spawn.calledWithExactly(testCommand, testArgs, {
'shell': false,
'shell': false, 'stdio': 'pipe',
})).is.true;
});
it('Should assign stdout data event', () => {
Expand Down

0 comments on commit 5eecd62

Please sign in to comment.