diff --git a/README.md b/README.md
index 7bfbff16..4f15b6cd 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,10 @@ The Xvfb constructor takes four options:
* silent
- don't pipe Xvfb stderr to the process's stderr.
* xvfb_args
- Extra arguments to pass to `Xvfb`.
+### Debugging
+
+Run with `DEBUG=xvfb` environment variable to see debug messages
+
### Thanks to
Forked from [node-xvfb](https://github.com/Rob--W/node-xvfb)
diff --git a/index.js b/index.js
index fae7b64a..fd773e4b 100644
--- a/index.js
+++ b/index.js
@@ -2,6 +2,7 @@
'use strict'
+const debug = require('debug')('xvfb')
const once = require('lodash.once')
const fs = require('fs')
const path = require('path')
@@ -11,7 +12,7 @@ fs.existsSync = fs.existsSync || path.existsSync
function Xvfb (options) {
options = options || {}
- this._display = (options.displayNum ? `:${options.displayNum}` : null)
+ this._display = options.displayNum ? `:${options.displayNum}` : null
this._reuse = options.reuse
this._timeout = options.timeout || 2000
this._silent = options.silent
@@ -39,8 +40,9 @@ Xvfb.prototype = {
return cb && cb(e)
}
- let totalTime = 0;
- (function checkIfStarted () {
+ let totalTime = 0
+ ;(function checkIfStarted () {
+ debug('checking if started by looking at the lock file', lockFile)
fs.exists(lockFile, function (exists) {
if (didSpawnFail) {
// When spawn fails, the callback will immediately be called.
@@ -71,8 +73,9 @@ Xvfb.prototype = {
self._restoreDisplayEnvVariable()
let lockFile = self._lockFile()
- let totalTime = 0;
- (function checkIfStopped () {
+ debug('lock file', lockFile)
+ let totalTime = 0
+ ;(function checkIfStopped () {
fs.exists(lockFile, function (exists) {
if (!exists) {
return cb && cb(null, self._process)
@@ -130,7 +133,9 @@ Xvfb.prototype = {
let display = self.display()
if (lockFileExists) {
if (!self._reuse) {
- throw new Error(`Display ${display} is already in use and the "reuse" option is false.`)
+ throw new Error(
+ `Display ${display} is already in use and the "reuse" option is false.`
+ )
}
} else {
const stderr = []
@@ -167,7 +172,11 @@ Xvfb.prototype = {
},
_lockFile (displayNum) {
- displayNum = displayNum || this.display().toString().replace(/^:/, '')
+ displayNum =
+ displayNum ||
+ this.display()
+ .toString()
+ .replace(/^:/, '')
return `/tmp/.X${displayNum}-lock`
},
}
diff --git a/package.json b/package.json
index 4d605df6..bce04178 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,7 @@
"url": "https://github.com/cypress-io/xvfb.git"
},
"dependencies": {
+ "debug": "^3.1.0",
"lodash.once": "^4.1.1"
},
"license": "MIT",