Files
cypress/cli/lib/exec/xvfb.js
2017-09-04 00:00:41 -04:00

39 lines
872 B
JavaScript

const os = require('os')
const Promise = require('bluebird')
const Xvfb = require('@cypress/xvfb')
const R = require('ramda')
const debug = require('debug')('cypress:cli')
const { throwFormErrorText, errors } = require('../errors')
const xvfb = Promise.promisifyAll(new Xvfb({ silent: true }))
module.exports = {
_xvfb: xvfb, // expose for testing
start () {
debug('Starting XVFB')
return xvfb.startAsync()
.catch(throwFormErrorText(errors.missingXvfb))
},
stop () {
debug('Stopping XVFB')
return xvfb.stopAsync()
},
isNeeded () {
return os.platform() === 'linux' && !process.env.DISPLAY
},
// async method, resolved with Boolean
verify () {
return xvfb.startAsync()
.then(R.T)
.catch((err) => {
debug('Could not verify xvfb: %s', err.message)
return false
})
.finally(xvfb.stopAsync)
},
}