Skip to content

Commit 36ef390

Browse files
committed
feat: add DEBUG=xvfb option close #7
1 parent 651ff8f commit 36ef390

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ The Xvfb constructor takes four options:
2626
* <code>silent</code> - don't pipe Xvfb stderr to the process's stderr.
2727
* <code>xvfb_args</code> - Extra arguments to pass to `Xvfb`.
2828

29+
### Debugging
30+
31+
Run with `DEBUG=xvfb` environment variable to see debug messages
32+
2933
### Thanks to
3034

3135
Forked from [node-xvfb](https://github.com/Rob--W/node-xvfb)

index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
'use strict'
44

5+
const debug = require('debug')('xvfb')
56
const once = require('lodash.once')
67
const fs = require('fs')
78
const path = require('path')
@@ -11,7 +12,7 @@ fs.existsSync = fs.existsSync || path.existsSync
1112

1213
function Xvfb (options) {
1314
options = options || {}
14-
this._display = (options.displayNum ? `:${options.displayNum}` : null)
15+
this._display = options.displayNum ? `:${options.displayNum}` : null
1516
this._reuse = options.reuse
1617
this._timeout = options.timeout || 2000
1718
this._silent = options.silent
@@ -39,8 +40,9 @@ Xvfb.prototype = {
3940
return cb && cb(e)
4041
}
4142

42-
let totalTime = 0;
43-
(function checkIfStarted () {
43+
let totalTime = 0
44+
;(function checkIfStarted () {
45+
debug('checking if started by looking at the lock file', lockFile)
4446
fs.exists(lockFile, function (exists) {
4547
if (didSpawnFail) {
4648
// When spawn fails, the callback will immediately be called.
@@ -71,8 +73,9 @@ Xvfb.prototype = {
7173
self._restoreDisplayEnvVariable()
7274

7375
let lockFile = self._lockFile()
74-
let totalTime = 0;
75-
(function checkIfStopped () {
76+
debug('lock file', lockFile)
77+
let totalTime = 0
78+
;(function checkIfStopped () {
7679
fs.exists(lockFile, function (exists) {
7780
if (!exists) {
7881
return cb && cb(null, self._process)
@@ -130,7 +133,9 @@ Xvfb.prototype = {
130133
let display = self.display()
131134
if (lockFileExists) {
132135
if (!self._reuse) {
133-
throw new Error(`Display ${display} is already in use and the "reuse" option is false.`)
136+
throw new Error(
137+
`Display ${display} is already in use and the "reuse" option is false.`
138+
)
134139
}
135140
} else {
136141
const stderr = []
@@ -167,7 +172,11 @@ Xvfb.prototype = {
167172
},
168173

169174
_lockFile (displayNum) {
170-
displayNum = displayNum || this.display().toString().replace(/^:/, '')
175+
displayNum =
176+
displayNum ||
177+
this.display()
178+
.toString()
179+
.replace(/^:/, '')
171180
return `/tmp/.X${displayNum}-lock`
172181
},
173182
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"url": "https://github.com/cypress-io/xvfb.git"
1616
},
1717
"dependencies": {
18+
"debug": "^3.1.0",
1819
"lodash.once": "^4.1.1"
1920
},
2021
"license": "MIT",

0 commit comments

Comments
 (0)