Files
cypress/packages/server/lib/exec.coffee
Chris Breiding d1fe365eca Add cy.task() command (#1422)
* server: handle undefined values from plugins

* server: have plugins process inherit stdio

so console.logs and such from plugins file come through

* add cy.task()

* server: fix config spec

* driver: fix task spec

* server: change ‘task’ to ‘task:requested’

* server: have ‘task’ event take object literal instead of function

* server: document how to run individual integration and e2e tests

* fix cy.task specs

* server: fix task e2e spec

* ensure stack trace comes through for task error

* don’t show stack for ‘known’ user errors

* add types for cy.task

* @sandbox -> sinon

* add e2e spec for task returning undefined

* update readme re: e2e —spec

* timedout -> timedOut

* new Promise + setTimeout -> Promise.delay

* improve cy.task() error messages

* fix specs
2018-05-15 20:49:20 -04:00

54 lines
1.4 KiB
CoffeeScript

Promise = require("bluebird")
execa = require("execa")
R = require("ramda")
shellEnv = require("shell-env")
log = require("./log")
utils = require("./util/shell")
pickMainProps = R.pick(["stdout", "stderr", "code"])
trimStdio = R.evolve({
stdout: R.trim,
stderr: R.trim
})
loadShellVars = R.memoize(shellEnv)
module.exports = {
run: (projectRoot, options) ->
cmd = options.cmd
shellCommand = (cmd, cwd, env, shell) ->
log("cy.exec found shell", shell)
log("and is running command:", options.cmd)
log("in folder:", projectRoot)
execa.shell(cmd, {cwd, env, shell})
# do we want to return all fields returned by execa?
.then (result) ->
result.shell = shell
result.cmd = cmd
result
.then pickMainProps
.catch pickMainProps # transform rejection into an object
.then trimStdio
run = ->
loadShellVars()
.then (shellVariables) ->
env = R.mergeAll([{}, shellVariables, process.env, options.env])
utils.getShell(env.SHELL)
.then (shell) ->
cmd = utils.sourceShellCommand(options.cmd, shell)
shellCommand(cmd, projectRoot, env, shell)
Promise
.try(run)
.timeout(options.timeout)
.catch Promise.TimeoutError, ->
msg = "Process timed out\ncommand: #{options.cmd}"
err = new Error(msg)
err.timedOut = true
throw err
}