Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show warning when binary is run directly (outside npm module) #4701

Merged
merged 14 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/lib/exec/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ module.exports = {
debug('needs to start own Xvfb?', needsXvfb)

// always push cwd into the args
// which additionally acts as a signal to the
// binary that it was invoked through the NPM module
args = [].concat(args, '--cwd', process.cwd())

_.defaults(options, {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"cypress:verify": "node ./cli/bin/cypress verify --dev",
"predecaffeinate-bulk": "shx cp .eslintrc.decaffeinate.js .eslintrc.js",
"decaffeinate-bulk": "bulk-decaffeinate",
"postdecaffeinate-bulk": "shx rm .eslintrc.js",
"dev": "node ./scripts/start.js",
"dev-debug": "node ./scripts/debug.js dev",
"docker": "./scripts/run-docker-local.sh",
Expand Down
10 changes: 9 additions & 1 deletion packages/server/lib/cypress.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ path = require("path")
Promise = require("bluebird")
debug = require("debug")("cypress:server:cypress")

warning = (code) ->
require("./errors").warning(code)

exit = (code = 0) ->
## TODO: we shouldn't have to do this
## but cannot figure out how null is
Expand All @@ -32,7 +35,7 @@ exitErr = (err) ->
## and exit with 1
debug('exiting with err', err)

require("./errors").log(err)
require("./errors").logException(err)
.then -> exit(1)

module.exports = {
Expand All @@ -49,6 +52,11 @@ module.exports = {
## like in production and we shouldn't spawn a new
## process
if @isCurrentlyRunningElectron()
## if we weren't invoked from the CLI
## then display a warning to the user
if not options.invokedFromCli
warning("INVOKED_BINARY_OUTSIDE_NPM_MODULE")

## just run the gui code directly here
## and pass our options directly to main
require("./modes")(mode, options)
Expand Down
55 changes: 39 additions & 16 deletions packages/server/lib/errors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Promise = require("bluebird")

twoOrMoreNewLinesRe = /\n{2,}/

isProduction = ->
process.env["CYPRESS_ENV"] is "production"

listItems = (paths) ->
_
.chain(paths)
Expand Down Expand Up @@ -690,6 +693,16 @@ getMsgByType = (type, arg1 = {}, arg2) ->

We looked but did not find a #{chalk.blue('cypress.json')} file in this folder: #{chalk.blue(arg1)}
"""
when "INVOKED_BINARY_OUTSIDE_NPM_MODULE"
"""
It looks like you are running the Cypress binary directly.

This is not the recommended approach, and Cypress may not work correctly.

Please install the 'cypress' NPM package and follow the instructions here:

https://on.cypress.io/installing-cypress
"""
when "DUPLICATE_TASK_KEY"
"""
Warning: Multiple attempts to register the following task(s): #{chalk.blue(arg1)}. Only the last attempt will be registered.
Expand Down Expand Up @@ -833,6 +846,8 @@ get = (type, arg1, arg2) ->
warning = (type, arg1, arg2) ->
err = get(type, arg1, arg2)
log(err, "magenta")

return null

throwErr = (type, arg1, arg2) ->
throw get(type, arg1, arg2)
Expand Down Expand Up @@ -860,27 +875,35 @@ clone = (err, options = {}) ->
obj

log = (err, color = "red") ->
Promise.try ->
console.log chalk[color](err.message)
if err.details
console.log("\n", chalk["yellow"](err.details))

## bail if this error came from known
## list of Cypress errors
return if isCypressErr(err)

console.log chalk[color](err.stack)

if process.env["CYPRESS_ENV"] is "production"
## log this error to raygun since its not
## a known error
require("./logger").createException(err).catch(->)

console.log chalk[color](err.message)

if err.details
console.log("\n", chalk["yellow"](err.details))

## bail if this error came from known
## list of Cypress errors
return if isCypressErr(err)

console.log chalk[color](err.stack)

return err

logException = Promise.method (err) ->
## TODO: remove context here
if @log(err) and isProduction()
## log this exception since
## its not a known error
return require("./logger")
.createException(err)
.catch(->)

module.exports = {
get,

log,

logException,

clone,

warning,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/modes/record.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ billingLink = (orgId) ->
gracePeriodMessage = (gracePeriodEnds) ->
gracePeriodEnds or "the grace period ends"

createRun = (options = {}) ->
createRun = Promise.method (options = {}) ->
_.defaults(options, {
group: null,
parallel: null,
Expand Down
Loading