Skip to content

Commit

Permalink
feat: add DEBUG=xvfb option close #7
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Dec 27, 2017
1 parent 651ff8f commit 36ef390
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,10 @@ The Xvfb constructor takes four options:
* <code>silent</code> - don't pipe Xvfb stderr to the process's stderr.
* <code>xvfb_args</code> - 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)
Expand Down
23 changes: 16 additions & 7 deletions index.js
Expand Up @@ -2,6 +2,7 @@

'use strict'

const debug = require('debug')('xvfb')
const once = require('lodash.once')
const fs = require('fs')
const path = require('path')
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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`
},
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -15,6 +15,7 @@
"url": "https://github.com/cypress-io/xvfb.git"
},
"dependencies": {
"debug": "^3.1.0",
"lodash.once": "^4.1.1"
},
"license": "MIT",
Expand Down

0 comments on commit 36ef390

Please sign in to comment.