Skip to content

Commit

Permalink
pass additional Electron launch args from env variable (#5891)
Browse files Browse the repository at this point in the history
* pass additional Electron launch args from env variable

* iterate over keys

* add environment test

* hmm, print error

* do not rethrow error

* do not swallow error in development, stub disable hw acc method

* use app.command.appendArgument
  • Loading branch information
bahmutov authored Dec 12, 2019
1 parent 6e9e6ab commit fe44330
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
43 changes: 26 additions & 17 deletions packages/server/lib/environment.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ Error.stackTraceLimit = Infinity
## would not be available
pkg = require("@packages/root")

## instead of setting NODE_ENV we will
## use our own separate CYPRESS_ENV so
## as not to conflict with CI providers

## use env from package first
## or development as default
env = process.env["CYPRESS_ENV"] or= pkg.env ? "development"

config = {
## uses cancellation for automation timeouts
cancellation: true
}

if env is "development"
## enable long stack traces in dev
config.longStackTraces = true

Promise.config(config)

# note: we print error in development mode only
try
## i wish we didn't have to do this but we have to append
## these command line switches immediately
Expand All @@ -39,23 +59,12 @@ try
if os.platform() is "linux"
app.disableHardwareAcceleration()

## instead of setting NODE_ENV we will
## use our own separate CYPRESS_ENV so
## as not to conflict with CI providers
if process.env.ELECTRON_EXTRA_LAUNCH_ARGS
electronLaunchArguments = process.env.ELECTRON_EXTRA_LAUNCH_ARGS.split(' ')
electronLaunchArguments.forEach app.commandLine.appendArgument

## use env from package first
## or development as default
env = process.env["CYPRESS_ENV"] or= pkg.env ? "development"

config = {
## uses cancellation for automation timeouts
cancellation: true
}

if env is "dev"
## enable long stack traces in dev
config.longStackTraces = true

Promise.config(config)
catch e
if env is "development"
console.error(e.message)

module.exports = env
4 changes: 3 additions & 1 deletion packages/server/test/support/helpers/electron_stub.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ module.exports = {
exit: ->
commandLine: {
appendSwitch: ->
}
appendArgument: ->
},
disableHardwareAcceleration: ->
}
systemPreferences: {
isDarkMode: ->
Expand Down
20 changes: 20 additions & 0 deletions packages/server/test/unit/environment_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require("../spec_helper")
Promise = require("bluebird")
pkg = require("@packages/root")
fs = require("#{root}lib/util/fs")
mockedEnv = require('mocked-env')
app = require("electron").app

setEnv = (env) =>
process.env["CYPRESS_ENV"] = env
Expand Down Expand Up @@ -31,6 +33,24 @@ describe "lib/environment", ->
after ->
process.env["CYPRESS_ENV"] = env

context "parses ELECTRON_EXTRA_LAUNCH_ARGS", ->
restore = null

beforeEach ->
restore = mockedEnv({
ELECTRON_EXTRA_LAUNCH_ARGS: "--foo --bar=baz --quux=true"
})

it "sets launch args", ->
sinon.stub(app.commandLine, "appendArgument")
require("#{root}lib/environment")
expect(app.commandLine.appendArgument).to.have.been.calledWith("--foo")
expect(app.commandLine.appendArgument).to.have.been.calledWith("--bar=baz")
expect(app.commandLine.appendArgument).to.have.been.calledWith("--quux=true")

afterEach ->
restore()

context "#existing process.env.CYPRESS_ENV", ->
it "is production", ->
setEnv("production")
Expand Down

4 comments on commit fe44330

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fe44330 Dec 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.8.0/win32-ia32/appveyor-develop-fe44330165fbbd6f0bf9e78515d1e641277c21ce-29505388/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.8.0/win32-ia32/appveyor-develop-fe44330165fbbd6f0bf9e78515d1e641277c21ce-29505388/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fe44330 Dec 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.8.0/linux-x64/circle-develop-fe44330165fbbd6f0bf9e78515d1e641277c21ce-213978/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.8.0/circle-develop-fe44330165fbbd6f0bf9e78515d1e641277c21ce-213946/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fe44330 Dec 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.8.0/win32-x64/appveyor-develop-fe44330165fbbd6f0bf9e78515d1e641277c21ce-29505388/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.8.0/win32-x64/appveyor-develop-fe44330165fbbd6f0bf9e78515d1e641277c21ce-29505388/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fe44330 Dec 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.8.0/darwin-x64/circle-develop-fe44330165fbbd6f0bf9e78515d1e641277c21ce-213998/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.8.0/circle-develop-fe44330165fbbd6f0bf9e78515d1e641277c21ce-213991/cypress.tgz

Please sign in to comment.