22
33'use strict' 
44
5+ const  debug  =  require ( 'debug' ) ( 'xvfb' ) 
56const  once  =  require ( 'lodash.once' ) 
67const  fs  =  require ( 'fs' ) 
78const  path  =  require ( 'path' ) 
@@ -11,7 +12,7 @@ fs.existsSync = fs.existsSync || path.existsSync
1112
1213function  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 }  ) 
136+         throw  new  Error ( 
137+           `Display ${ display }  
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 }  
172181  } , 
173182} 
0 commit comments