From 139aeed77fd400ff4c02f81bf623cc10d26388c7 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Tue, 27 Aug 2019 11:52:30 -0400 Subject: [PATCH 1/4] cli: pipe stdin --- cli/lib/exec/spawn.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cli/lib/exec/spawn.js b/cli/lib/exec/spawn.js index dbb9a6507473..55aa29aaae76 100644 --- a/cli/lib/exec/spawn.js +++ b/cli/lib/exec/spawn.js @@ -135,12 +135,25 @@ module.exports = { child.on('close', resolve) child.on('error', reject) - child.stdin && child.stdin.pipe(process.stdin) - child.stdout && child.stdout.pipe(process.stdout) + // if stdio options is set to 'pipe', then + // we should set up pipes: + // process STDIN (read stream) => child STDIN (writeable) + // child STDOUT => process STDOUT + // child STDERR => process STDERR with additional filtering + if (child.stdin) { + debug('piping process STDIN into child STDIN') + child.stdin.pipe(process.stdin) + } + + if (child.stdout) { + debug('piping child STDOUT to process STDOUT') + child.stdout.pipe(process.stdout) + } // if this is defined then we are manually piping for linux // to filter out the garbage - child.stderr && + if (child.stderr) { + debug('piping child STDERR to process STDERR') child.stderr.on('data', (data) => { const str = data.toString() @@ -158,6 +171,7 @@ module.exports = { // else pass it along! process.stderr.write(data) }) + } // https://github.com/cypress-io/cypress/issues/1841 // In some versions of node, it will throw on windows From b036c92d2cfba0a35655c70b2183dfbe4df34096 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Tue, 27 Aug 2019 12:09:52 -0400 Subject: [PATCH 2/4] uggh, here is the actual change --- cli/lib/exec/spawn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/lib/exec/spawn.js b/cli/lib/exec/spawn.js index 55aa29aaae76..2f235f418a68 100644 --- a/cli/lib/exec/spawn.js +++ b/cli/lib/exec/spawn.js @@ -142,7 +142,7 @@ module.exports = { // child STDERR => process STDERR with additional filtering if (child.stdin) { debug('piping process STDIN into child STDIN') - child.stdin.pipe(process.stdin) + process.stdin.pipe(child.stdin) } if (child.stdout) { From a314c2c6c6cfc04774b683ef5abc28c0bdda832d Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Tue, 27 Aug 2019 12:25:56 -0400 Subject: [PATCH 3/4] update cli unit tests --- cli/test/lib/exec/spawn_spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/test/lib/exec/spawn_spec.js b/cli/test/lib/exec/spawn_spec.js index 75f46650ef5b..5e028ebd3d58 100644 --- a/cli/test/lib/exec/spawn_spec.js +++ b/cli/test/lib/exec/spawn_spec.js @@ -39,7 +39,11 @@ describe('lib/exec/spawn', function () { }, } - sinon.stub(process, 'stdin').value(new EE) + // process.stdin is both an event emitter and a readable stream + const processStdin = new EE() + + processStdin.pipe = sinon.stub().returns(undefined) + sinon.stub(process, 'stdin').value(processStdin) sinon.stub(cp, 'spawn').returns(this.spawnedProcess) sinon.stub(xvfb, 'start').resolves() sinon.stub(xvfb, 'stop').resolves() From 7dd8ba3362d035d8e5188acb360455ac872942b4 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Tue, 27 Aug 2019 15:46:53 -0400 Subject: [PATCH 4/4] add unit test --- cli/test/lib/exec/spawn_spec.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cli/test/lib/exec/spawn_spec.js b/cli/test/lib/exec/spawn_spec.js index 5e028ebd3d58..9cfd1e64d1b3 100644 --- a/cli/test/lib/exec/spawn_spec.js +++ b/cli/test/lib/exec/spawn_spec.js @@ -40,10 +40,9 @@ describe('lib/exec/spawn', function () { } // process.stdin is both an event emitter and a readable stream - const processStdin = new EE() - - processStdin.pipe = sinon.stub().returns(undefined) - sinon.stub(process, 'stdin').value(processStdin) + this.processStdin = new EE() + this.processStdin.pipe = sinon.stub().returns(undefined) + sinon.stub(process, 'stdin').value(this.processStdin) sinon.stub(cp, 'spawn').returns(this.spawnedProcess) sinon.stub(xvfb, 'start').resolves() sinon.stub(xvfb, 'stop').resolves() @@ -296,6 +295,9 @@ describe('lib/exec/spawn', function () { return spawn.start() .then(() => { expect(cp.spawn.firstCall.args[2].stdio).to.deep.eq('pipe') + // parent process STDIN was piped to child process STDIN + expect(this.processStdin.pipe, 'process.stdin').to.have.been.calledOnce + .and.to.have.been.calledWith(this.spawnedProcess.stdin) }) })