Skip to content

Commit

Permalink
Merge branch 'develop' into issue-5859-env-vars-show-undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes authored Dec 12, 2019
2 parents 5423399 + fe44330 commit e1a97a1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 27 deletions.
5 changes: 4 additions & 1 deletion packages/driver/src/cy/commands/request.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ module.exports = (Commands, Cypress, cy, state, config) ->
## https://github.com/cypress-io/cypress/issues/5274
try
options.url = new URL(options.url).href
catch TypeError
catch err
if !(err instanceof TypeError) ## unexpected, new URL should only throw TypeError
throw err

# The URL object cannot be constructed because of URL failure
$utils.throwErrByPath("request.url_invalid", {
args: {
Expand Down
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
18 changes: 10 additions & 8 deletions packages/server/lib/open_project.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const preprocessor = require('./plugins/preprocessor')
const moduleFactory = () => {
let openProject = null
let relaunchBrowser = null
let specsWatcher = null

const reset = () => {
openProject = null
Expand All @@ -29,6 +28,8 @@ const moduleFactory = () => {
}

return {
specsWatcher: null,

reset: tryToCall('reset'),

getConfig: tryToCall('getConfig'),
Expand Down Expand Up @@ -165,21 +166,21 @@ const moduleFactory = () => {
250, { leading: true })

const createSpecsWatcher = (cfg) => {
if (specsWatcher) {
if (this.specsWatcher) {
return
}

debug('watch test files: %s in %s', cfg.testFiles, cfg.integrationFolder)

specsWatcher = chokidar.watch(cfg.testFiles, {
this.specsWatcher = chokidar.watch(cfg.testFiles, {
cwd: cfg.integrationFolder,
ignored: cfg.ignoreTestFiles,
ignoreInitial: true,
})

specsWatcher.on('add', checkForSpecUpdates)
this.specsWatcher.on('add', checkForSpecUpdates)

return specsWatcher.on('unlink', checkForSpecUpdates)
return this.specsWatcher.on('unlink', checkForSpecUpdates)
}

const get = () => {
Expand All @@ -205,9 +206,10 @@ const moduleFactory = () => {
stopSpecsWatcher () {
debug('stop spec watcher')

return Promise.try(() => {
return specsWatcher ? specsWatcher.close() : undefined
})
if (this.specsWatcher) {
this.specsWatcher.close()
this.specsWatcher = null
}
},

closeBrowser () {
Expand Down
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
11 changes: 11 additions & 0 deletions packages/server/test/unit/open_project_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe('lib/open_project', () => {
beforeEach(function () {
this.watcherStub = {
on: sinon.stub(),
close: sinon.stub(),
}

sinon.stub(chokidar, 'watch').returns(this.watcherStub)
Expand Down Expand Up @@ -141,5 +142,15 @@ describe('lib/open_project', () => {
expect(onChange).to.be.calledOnce
})
})

it('destroys and creates specsWatcher as expected', function () {
expect(openProject.specsWatcher).to.exist
openProject.stopSpecsWatcher()
expect(openProject.specsWatcher).to.be.null
openProject.getSpecChanges()
.then(() => {
expect(openProject.specsWatcher).to.exist
})
})
})
})

0 comments on commit e1a97a1

Please sign in to comment.