Skip to content

Commit

Permalink
cli: fix the STDIN pipe on Windows (#5045)
Browse files Browse the repository at this point in the history
* cli: pipe stdin

* uggh, here is the actual change

* update cli unit tests

* add unit test
  • Loading branch information
bahmutov authored Sep 19, 2019
1 parent 9f717fe commit 084f25f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 17 additions & 3 deletions cli/lib/exec/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
process.stdin.pipe(child.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()

Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion cli/test/lib/exec/spawn_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ describe('lib/exec/spawn', function () {
},
}

sinon.stub(process, 'stdin').value(new EE)
// process.stdin is both an event emitter and a readable stream
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()
Expand Down Expand Up @@ -292,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)
})
})

Expand Down

4 comments on commit 084f25f

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 084f25f Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/linux-x64/circle-develop-084f25f0927cb1da2780e4e8697338c0ddc5db25-152848/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.5.0/circle-develop-084f25f0927cb1da2780e4e8697338c0ddc5db25-152832/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 084f25f Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-084f25f0927cb1da2780e4e8697338c0ddc5db25-27531153/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-084f25f0927cb1da2780e4e8697338c0ddc5db25-27531153/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 084f25f Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-084f25f0927cb1da2780e4e8697338c0ddc5db25-27531153/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-084f25f0927cb1da2780e4e8697338c0ddc5db25-27531153/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 084f25f Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/darwin-x64/circle-develop-084f25f0927cb1da2780e4e8697338c0ddc5db25-152860/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.5.0/circle-develop-084f25f0927cb1da2780e4e8697338c0ddc5db25-152859/cypress.tgz

Please sign in to comment.