Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8aa1922

Browse files
authored
dont blow away the default electron options (cypress-io#1993)
fixes cypress-io#1992
1 parent f90bfbe commit 8aa1922

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

packages/server/lib/browsers/electron.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ module.exports = {
126126

127127
plugins.execute("before:browser:launch", options.browser, options)
128128
.then (newOptions) ->
129-
return newOptions ? options
129+
if newOptions
130+
_.extend(options, newOptions)
131+
132+
return options
130133
.then (options) =>
131134
@_render(url, projectRoot, options)
132135
.then (win) =>

packages/server/test/integration/cypress_spec.coffee

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,11 @@ describe "lib/cypress", ->
734734
ee.loadURL = ->
735735
ee.focusOnWebView = ->
736736
ee.webContents = {
737+
setUserAgent: sinon.stub()
737738
session: {
738739
clearCache: sinon.stub().yieldsAsync()
740+
setProxy: sinon.stub().yieldsAsync()
741+
setUserAgent: sinon.stub()
739742
}
740743
}
741744

@@ -765,14 +768,19 @@ describe "lib/cypress", ->
765768
@expectExitWith(0)
766769

767770
it "electron", ->
771+
write = sinon.stub()
772+
videoCapture.start.returns({ write })
773+
768774
cypress.start([
769775
"--run-project=#{@pluginBrowser}"
770776
"--browser=electron"
771777
])
772778
.then =>
773-
expect(Windows.create).to.be.calledWith(@pluginBrowser, {
779+
expect(Windows.create).to.be.calledWithMatch(@pluginBrowser, {
774780
browser: "electron"
775781
foo: "bar"
782+
onNewWindow: sinon.match.func
783+
onPaint: sinon.match.func
776784
})
777785

778786
@expectExitWith(0)

packages/server/test/unit/browsers/electron_spec.coffee

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ la = require("lazy-ass")
66
check = require("check-more-types")
77

88
menu = require("#{root}../lib/gui/menu")
9+
plugins = require("#{root}../lib/plugins")
910
Windows = require("#{root}../lib/gui/windows")
1011
electron = require("#{root}../lib/browsers/electron")
1112
savedState = require("#{root}../lib/saved_state")
@@ -38,6 +39,9 @@ describe "lib/browsers/electron", ->
3839
context ".open", ->
3940
beforeEach ->
4041
sinon.stub(electron, "_render").resolves(@win)
42+
sinon.stub(plugins, "has")
43+
sinon.stub(plugins, "execute")
44+
4145
savedState()
4246
.then (state) =>
4347
la(check.fn(state.get), "state is missing .get to stub", state)
@@ -74,6 +78,27 @@ describe "lib/browsers/electron", ->
7478
expect(@automation.use).to.be.called
7579
expect(@automation.use.lastCall.args[0].onRequest).to.be.a("function")
7680

81+
it "is noop when before:browser:launch yields null", ->
82+
plugins.has.returns(true)
83+
plugins.execute.resolves(null)
84+
85+
electron.open("electron", @url, @options, @automation)
86+
.then =>
87+
options = electron._render.firstCall.args[2]
88+
89+
expect(options).to.include.keys("onFocus", "onNewWindow", "onPaint", "onCrashed")
90+
91+
## https://github.com/cypress-io/cypress/issues/1992
92+
it "it merges in options without removing essential options", ->
93+
plugins.has.returns(true)
94+
plugins.execute.resolves({foo: "bar"})
95+
96+
electron.open("electron", @url, @options, @automation)
97+
.then =>
98+
options = electron._render.firstCall.args[2]
99+
100+
expect(options).to.include.keys("foo", "onFocus", "onNewWindow", "onPaint", "onCrashed")
101+
77102
context "._launch", ->
78103
beforeEach ->
79104
sinon.stub(menu, "set")

0 commit comments

Comments
 (0)