-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
xvfb.js
58 lines (47 loc) · 1.23 KB
/
xvfb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const os = require('os')
const Promise = require('bluebird')
const Xvfb = require('@cypress/xvfb')
const R = require('ramda')
const debug = require('debug')('cypress:cli')
const debugXvfb = require('debug')('cypress:xvfb')
const { throwFormErrorText, errors } = require('../errors')
const xvfb = Promise.promisifyAll(new Xvfb({
timeout: 5000, // milliseconds
onStderrData (data) {
if (debugXvfb.enabled) {
debugXvfb(data.toString())
}
},
}))
module.exports = {
_debugXvfb: debugXvfb, // expose for testing
_xvfb: xvfb, // expose for testing
start () {
debug('Starting XVFB')
return xvfb.startAsync()
.catch({ nonZeroExitCode: true }, throwFormErrorText(errors.nonZeroExitCodeXvfb))
.catch((err) => {
if (err.known) {
throw err
}
return throwFormErrorText(errors.missingXvfb)(err)
})
},
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)
},
}