-_       = require("lodash")
-cp      = require("child_process")
-os      = require("os")
-fs      = require("fs-extra")
-path    = require("path")
-chalk   = require("chalk")
-Xvfb    = require("xvfb")
-Promise = require("bluebird")
+_        = require("lodash")
+cp       = require("child_process")
+os       = require("os")
+fs       = require("fs-extra")
+path     = require("path")
+chalk    = require("chalk")
+Xvfb     = require("xvfb")
+userhome = require("userhome")
+Promise  = require("bluebird")
 
 fs   = Promise.promisifyAll(fs)
 xvfb = Promise.promisifyAll(new Xvfb({silent: true}))

      console.log("")
      process.exit(1)

  spawn: (args, options = {}) ->
    ## this needs to change to become async and
    ## to do a lookup for the cached cypress path

    args = [].concat(args)

    _.defaults options,
      xvfb: os.platform() is "linux"
      stdio: ["ignore", process.stdout, "ignore"]

    spawn = =>
      @verifyCypress(cypress).then ->
        sp = cp.spawn cypress, args, options
        if options.xvfb
          ## make sure we close down xvfb
          ## when our spawned process exits
          sp.on "close", @stopXvfb

    if options.xvfb
      @startXvfb().then(spawn)
