Skip to content

Commit a724d4f

Browse files
committed
depromisify things that were promisified b/t electron 5 <=> 6
Revert "update shell.openExternal to promisified" This reverts commit 8b6460d. Revert "update dialog.showOpenDialog to promisified" This reverts commit 5f178b0. Revert "update webContents.session.setProxy to promisified" This reverts commit 727df3a.
1 parent 1e698b5 commit a724d4f

File tree

6 files changed

+44
-41
lines changed

6 files changed

+44
-41
lines changed

packages/server/lib/browsers/electron.coffee

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ getAutomation = (win) ->
9393
.then ->
9494
cookieToBeCleared
9595
when "is:automation:client:connected"
96-
tryToCall(win, 'isDestroyed') == false
96+
true
9797
when "take:screenshot"
9898
tryToCall(win, 'capturePage')
9999
.then _.partialRight(_.invoke, 'toDataURL')
@@ -194,18 +194,16 @@ module.exports = {
194194

195195
_attachDebugger: (webContents) ->
196196
originalSendCommand = webContents.debugger.sendCommand
197-
webContents.debugger.sendCommand = (message, data = {}) ->
198-
debug('debugger: sending %s %o', message, data)
199-
200-
originalSendCommand
201-
.call(webContents.debugger, message, data)
202-
.then (result) =>
203-
debug("debugger: received response for %s: result: %o", message, result)
204-
result
205-
.catch (err) =>
206-
debug("debugger: received error on %s: result: %o", message, err)
207-
throw err
208197

198+
webContents.debugger.sendCommand = (message, data = {}) ->
199+
new Promise (resolve, reject) =>
200+
debug('debugger: sending %s %o', message, data)
201+
202+
originalSendCommand.call webContents.debugger, message, data, (err, result) =>
203+
debug("debugger: received response for %s: %o", message, { err, result })
204+
if _.isEmpty(err)
205+
return resolve(result)
206+
reject(err)
209207
try
210208
webContents.debugger.attach()
211209
debug("debugger attached")
@@ -240,7 +238,8 @@ module.exports = {
240238

241239
_clearCache: (webContents) ->
242240
debug("clearing cache")
243-
webContents.session.clearCache()
241+
Promise.fromCallback (cb) =>
242+
webContents.session.clearCache(cb)
244243

245244
_setUserAgent: (webContents, userAgent) ->
246245
debug("setting user agent to:", userAgent)
@@ -249,13 +248,14 @@ module.exports = {
249248
webContents.session.setUserAgent(userAgent)
250249

251250
_setProxy: (webContents, proxyServer) ->
252-
webContents.session.setProxy({
253-
proxyRules: proxyServer
254-
## this should really only be necessary when
255-
## running Chromium versions >= 72
256-
## https://github.com/cypress-io/cypress/issues/1872
257-
proxyBypassRules: "<-loopback>"
258-
})
251+
Promise.fromCallback (cb) =>
252+
webContents.session.setProxy({
253+
proxyRules: proxyServer
254+
## this should really only be necessary when
255+
## running Chromium versions >= 72
256+
## https://github.com/cypress-io/cypress/issues/1872
257+
proxyBypassRules: "<-loopback>"
258+
}, cb)
259259

260260
open: (browser, url, options = {}, automation) ->
261261
{ projectRoot, isTextTerminal } = options

packages/server/lib/gui/auth.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ const _launchNativeAuth = Promise.method((loginUrl, sendMessage) => {
190190

191191
openExternalAttempted = true
192192

193-
return shell.openExternal(loginUrl)
193+
// wrap openExternal here in case `electron.shell` is not available (during tests)
194+
return Promise.fromCallback((cb) => {
195+
shell.openExternal(loginUrl, {}, cb)
196+
})
194197
.catch((err) => {
195198
debug('Error launching native auth: %o', { err })
196199
warnCouldNotLaunch()

packages/server/lib/gui/dialog.coffee

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ module.exports = {
1515
properties: ["openDirectory"]
1616
}
1717

18-
dialog.showOpenDialog(props)
19-
.then ({ filePaths }) ->
20-
return filePaths[0]
18+
new Promise (resolve, reject) ->
19+
dialog.showOpenDialog props, (paths = []) ->
20+
process.nextTick ->
21+
## return the first path since there can only ever
22+
## be a single directory selection
23+
resolve(paths[0])
2124
}

packages/server/lib/gui/windows.coffee

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ setWindowProxy = (win) ->
3434
if not process.env.HTTP_PROXY
3535
return
3636

37-
win.webContents.session.setProxy({
38-
proxyRules: process.env.HTTP_PROXY
39-
proxyBypassRules: process.env.NO_PROXY
40-
})
37+
return new Promise (resolve) ->
38+
win.webContents.session.setProxy({
39+
proxyRules: process.env.HTTP_PROXY
40+
proxyBypassRules: process.env.NO_PROXY
41+
}, resolve)
4142

4243
module.exports = {
4344
reset: ->

packages/server/test/unit/gui/auth_spec.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,21 @@ describe('lib/gui/auth', function () {
8888
})
8989

9090
it('returns a promise that is fulfilled when openExternal succeeds', function () {
91-
sinon.stub(electron.shell, 'openExternal').resolves()
92-
const sendWarning = sinon.stub()
91+
sinon.stub(electron.shell, 'openExternal').callsArg(2)
9392

94-
return auth._launchNativeAuth(REDIRECT_URL, sendWarning)
93+
return auth._launchNativeAuth(REDIRECT_URL)
9594
.then(() => {
96-
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL)
97-
expect(sendWarning).to.not.be.called
95+
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL, {}, sinon.match.func)
9896
})
9997
})
10098

10199
it('is still fulfilled when openExternal fails, but sendWarning is called', function () {
102-
sinon.stub(electron.shell, 'openExternal').rejects(new Error)
100+
sinon.stub(electron.shell, 'openExternal').callsArgWith(2, new Error)
103101
const sendWarning = sinon.stub()
104102

105103
return auth._launchNativeAuth(REDIRECT_URL, sendWarning)
106104
.then(() => {
107-
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL)
105+
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL, {}, sinon.match.func)
108106
expect(sendWarning).to.be.calledWithMatch('warning', 'AUTH_COULD_NOT_LAUNCH_BROWSER', REDIRECT_URL)
109107
})
110108
})

packages/server/test/unit/gui/dialog_spec.coffee

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ Windows = require("#{root}../lib/gui/windows")
77
describe "gui/dialog", ->
88
context ".show", ->
99
beforeEach ->
10-
@showOpenDialog = electron.dialog.showOpenDialog = sinon.stub().resolves({
11-
filePaths: []
12-
})
10+
@showOpenDialog = electron.dialog.showOpenDialog = sinon.stub()
1311

1412
it "calls dialog.showOpenDialog with args", ->
1513
dialog.show()
@@ -18,13 +16,13 @@ describe "gui/dialog", ->
1816
})
1917

2018
it "resolves with first path", ->
21-
@showOpenDialog.resolves({
22-
filePaths: ["foo", "bar"]
23-
})
19+
@showOpenDialog.yields(["foo", "bar"])
2420

2521
dialog.show().then (ret) ->
2622
expect(ret).to.eq("foo")
2723

2824
it "handles null paths", ->
25+
@showOpenDialog.yields(null)
26+
2927
dialog.show().then (ret) ->
3028
expect(ret).to.eq(undefined)

0 commit comments

Comments
 (0)