Files
cypress/packages/server/lib/exec.js
T
decaffeinate e7d1f313b0 decaffeinate: Run post-processing cleanups on api.coffee and 35 other files
decaffeinate: Run post-processing cleanups on reporter.coffee
2020-06-04 14:03:03 -04:00

73 lines
1.9 KiB
JavaScript

// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const Promise = require('bluebird')
const execa = require('execa')
const R = require('ramda')
const shellEnv = require('shell-env')
const log = require('./log')
const utils = require('./util/shell')
const pickMainProps = R.pick(['stdout', 'stderr', 'code'])
const trimStdio = R.evolve({
stdout: R.trim,
stderr: R.trim,
})
const loadShellVars = R.memoize(shellEnv)
module.exports = {
run (projectRoot, options) {
let {
cmd,
} = options
const shellCommand = function (cmd, cwd, env, shell) {
log('cy.exec found shell', shell)
log('and is running command:', options.cmd)
log('in folder:', projectRoot)
return execa.shell(cmd, { cwd, env, shell })
// do we want to return all fields returned by execa?
.then((result) => {
result.shell = shell
result.cmd = cmd
return result
}).then(pickMainProps)
.catch(pickMainProps) // transform rejection into an object
.then(trimStdio)
}
const run = () => {
return loadShellVars()
.then((shellVariables) => {
const env = R.mergeAll([{}, shellVariables, process.env, options.env])
return utils.getShell(env.SHELL)
.then((shell) => {
cmd = utils.sourceShellCommand(options.cmd, shell)
return shellCommand(cmd, projectRoot, env, shell)
})
})
}
return Promise
.try(run)
.timeout(options.timeout)
.catch(Promise.TimeoutError, () => {
const msg = `Process timed out\ncommand: ${options.cmd}`
const err = new Error(msg)
err.timedOut = true
throw err
})
},
}