catch EPIPE errors (#2011)

fixes #1841
This commit is contained in:
Brian Mann
2018-06-21 18:29:27 -04:00
committed by GitHub
parent ace7e97675
commit df0ec8ea8c
2 changed files with 50 additions and 0 deletions
+36
View File
@@ -4,6 +4,7 @@ const cp = require('child_process')
const os = require('os')
const tty = require('tty')
const path = require('path')
const EE = require('events')
const state = require(`${lib}/tasks/state`)
const xvfb = require(`${lib}/exec/xvfb`)
@@ -35,6 +36,7 @@ describe('lib/exec/spawn', function () {
on: sinon.stub().returns(undefined),
},
}
sinon.stub(process, 'stdin').value(new EE)
sinon.stub(cp, 'spawn').returns(this.spawnedProcess)
sinon.stub(xvfb, 'start').resolves()
sinon.stub(xvfb, 'stop').resolves()
@@ -313,5 +315,39 @@ describe('lib/exec/spawn', function () {
expect(process.stderr.write).not.to.be.calledWith(buf1)
})
})
it('catches process.stdin errors and returns when code=EPIPE', function () {
this.spawnedProcess.on.withArgs('close').yieldsAsync(0)
return spawn.start()
.then(() => {
let called = false
const fn = () => {
called = true
const err = new Error()
err.code = 'EPIPE'
return process.stdin.emit('error', err)
}
expect(fn).not.to.throw()
expect(called).to.be.true
})
})
it('throws process.stdin errors code!=EPIPE', function () {
this.spawnedProcess.on.withArgs('close').yieldsAsync(0)
return spawn.start()
.then(() => {
const fn = () => {
const err = new Error('wattttt')
err.code = 'FAILWHALE'
return process.stdin.emit('error', err)
}
expect(fn).to.throw(/wattttt/)
})
})
})
})