windows: solve shell exec problem

Cypress executes multiple exec commands in local and global mode correctly
This commit is contained in:
Gleb Bahmutov
2017-09-28 19:22:32 -07:00
parent f0a1296d95
commit 449537a7ea
2 changed files with 31 additions and 3 deletions

View File

@@ -5,7 +5,7 @@ shellEnv = require("shell-env")
log = require("./log")
utils = require("./util/shell")
pickMainProps = R.pick(["stdout", "stderr", "code"])
pickMainProps = R.pick(["stdout", "stderr", "code", "shell", "cmd"])
trimStdio = R.evolve({
stdout: R.trim,

View File

@@ -1,8 +1,12 @@
Promise = require("bluebird")
execa = require("execa")
R = require("ramda")
os = require("os")
log = require("../log")
isWindows = ->
os.platform() == "win32"
profiles = {
"~/.profile": /\/sh$/
"~/.bash_profile": /\/bash$/
@@ -14,18 +18,37 @@ profiles = {
sourcedProfiles = []
## returns true if Cypress application has been started from
## the terminal shell.
## returns false if Cypress application has been started
## from the Finder / Windows Explorer list
## by double clicking its icon
startedNormally = ->
Boolean(process.env._)
getProfilePath = (shellPath) ->
for profilePath, regex of profiles
return profilePath if regex.test(shellPath)
sourceShellCommand = (cmd, shell) ->
if not shell
return cmd
profilePath = getProfilePath(shell)
log("shell %s profile %s", shell, profilePath)
if sourcedProfiles.includes(profilePath)
log "profile has already been sourced"
cmd
else
sourcedProfiles.push(profilePath)
haveShell = startedNormally()
if haveShell
## we only need to source once
## IF THE APP HAS NOT BEEN STARTED BY
## DOUBLE CLICKING IT FROM FINDER / WINDOWS EXPLORER
## OTHERWISE NEED TO SOURCE EVERY COMMAND
sourcedProfiles.push(profilePath)
## sourcing the profile can output un-needed garbage,
## so suppress it by sending it to /dev/null and ignore
## any failures with this
"source #{profilePath} > /dev/null 2>&1; #{cmd}"
findBash = ->
@@ -40,6 +63,10 @@ getShell = (shell) ->
if s = process.env.SHELL
return Promise.resolve(s)
if isWindows()
log("use default shell on Windows")
return Promise.resolve()
findBash()
# for testing
@@ -51,5 +78,6 @@ module.exports = {
findBash,
getShell,
getProfilePath,
sourceShellCommand
sourceShellCommand,
startedNormally
}