From ebdfd5a7b55e62fad517805d39424b04d1efb788 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Tue, 24 Sep 2019 12:23:12 -0400 Subject: [PATCH 1/5] Revert "depromisify things that were promisified b/t electron 5 <=> 6" This reverts commit a724d4f127ac31d64033409e8748ed15d244c234. --- packages/server/lib/browsers/electron.coffee | 40 +++++++++---------- packages/server/lib/gui/auth.js | 5 +-- packages/server/lib/gui/dialog.coffee | 9 ++--- packages/server/lib/gui/windows.coffee | 9 ++--- packages/server/test/unit/gui/auth_spec.js | 12 +++--- .../server/test/unit/gui/dialog_spec.coffee | 10 +++-- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/packages/server/lib/browsers/electron.coffee b/packages/server/lib/browsers/electron.coffee index 338a6fb1c7d2..e25cfd3e6841 100644 --- a/packages/server/lib/browsers/electron.coffee +++ b/packages/server/lib/browsers/electron.coffee @@ -93,7 +93,7 @@ getAutomation = (win) -> .then -> cookieToBeCleared when "is:automation:client:connected" - true + tryToCall(win, 'isDestroyed') == false when "take:screenshot" tryToCall(win, 'capturePage') .then _.partialRight(_.invoke, 'toDataURL') @@ -194,16 +194,18 @@ module.exports = { _attachDebugger: (webContents) -> originalSendCommand = webContents.debugger.sendCommand - webContents.debugger.sendCommand = (message, data = {}) -> - new Promise (resolve, reject) => - debug('debugger: sending %s %o', message, data) - - originalSendCommand.call webContents.debugger, message, data, (err, result) => - debug("debugger: received response for %s: %o", message, { err, result }) - if _.isEmpty(err) - return resolve(result) - reject(err) + debug('debugger: sending %s %o', message, data) + + originalSendCommand + .call(webContents.debugger, message, data) + .then (result) => + debug("debugger: received response for %s: result: %o", message, result) + result + .catch (err) => + debug("debugger: received error on %s: result: %o", message, err) + throw err + try webContents.debugger.attach() debug("debugger attached") @@ -238,8 +240,7 @@ module.exports = { _clearCache: (webContents) -> debug("clearing cache") - Promise.fromCallback (cb) => - webContents.session.clearCache(cb) + webContents.session.clearCache() _setUserAgent: (webContents, userAgent) -> debug("setting user agent to:", userAgent) @@ -248,14 +249,13 @@ module.exports = { webContents.session.setUserAgent(userAgent) _setProxy: (webContents, proxyServer) -> - Promise.fromCallback (cb) => - webContents.session.setProxy({ - proxyRules: proxyServer - ## this should really only be necessary when - ## running Chromium versions >= 72 - ## https://github.com/cypress-io/cypress/issues/1872 - proxyBypassRules: "<-loopback>" - }, cb) + webContents.session.setProxy({ + proxyRules: proxyServer + ## this should really only be necessary when + ## running Chromium versions >= 72 + ## https://github.com/cypress-io/cypress/issues/1872 + proxyBypassRules: "<-loopback>" + }) open: (browser, url, options = {}, automation) -> { projectRoot, isTextTerminal } = options diff --git a/packages/server/lib/gui/auth.js b/packages/server/lib/gui/auth.js index 99882e628b6d..79f14a0446fc 100644 --- a/packages/server/lib/gui/auth.js +++ b/packages/server/lib/gui/auth.js @@ -190,10 +190,7 @@ const _launchNativeAuth = Promise.method((loginUrl, sendMessage) => { openExternalAttempted = true - // wrap openExternal here in case `electron.shell` is not available (during tests) - return Promise.fromCallback((cb) => { - shell.openExternal(loginUrl, {}, cb) - }) + return shell.openExternal(loginUrl) .catch((err) => { debug('Error launching native auth: %o', { err }) warnCouldNotLaunch() diff --git a/packages/server/lib/gui/dialog.coffee b/packages/server/lib/gui/dialog.coffee index c95cddd2ad8b..2531c09d044c 100644 --- a/packages/server/lib/gui/dialog.coffee +++ b/packages/server/lib/gui/dialog.coffee @@ -15,10 +15,7 @@ module.exports = { properties: ["openDirectory"] } - new Promise (resolve, reject) -> - dialog.showOpenDialog props, (paths = []) -> - process.nextTick -> - ## return the first path since there can only ever - ## be a single directory selection - resolve(paths[0]) + dialog.showOpenDialog(props) + .then ({ filePaths }) -> + return filePaths[0] } diff --git a/packages/server/lib/gui/windows.coffee b/packages/server/lib/gui/windows.coffee index 2210888e5fce..1667200ae68c 100644 --- a/packages/server/lib/gui/windows.coffee +++ b/packages/server/lib/gui/windows.coffee @@ -34,11 +34,10 @@ setWindowProxy = (win) -> if not process.env.HTTP_PROXY return - return new Promise (resolve) -> - win.webContents.session.setProxy({ - proxyRules: process.env.HTTP_PROXY - proxyBypassRules: process.env.NO_PROXY - }, resolve) + win.webContents.session.setProxy({ + proxyRules: process.env.HTTP_PROXY + proxyBypassRules: process.env.NO_PROXY + }) module.exports = { reset: -> diff --git a/packages/server/test/unit/gui/auth_spec.js b/packages/server/test/unit/gui/auth_spec.js index 98a329b52195..51c09ef967fd 100644 --- a/packages/server/test/unit/gui/auth_spec.js +++ b/packages/server/test/unit/gui/auth_spec.js @@ -88,21 +88,23 @@ describe('lib/gui/auth', function () { }) it('returns a promise that is fulfilled when openExternal succeeds', function () { - sinon.stub(electron.shell, 'openExternal').callsArg(2) + sinon.stub(electron.shell, 'openExternal').resolves() + const sendWarning = sinon.stub() - return auth._launchNativeAuth(REDIRECT_URL) + return auth._launchNativeAuth(REDIRECT_URL, sendWarning) .then(() => { - expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL, {}, sinon.match.func) + expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL) + expect(sendWarning).to.not.be.called }) }) it('is still fulfilled when openExternal fails, but sendWarning is called', function () { - sinon.stub(electron.shell, 'openExternal').callsArgWith(2, new Error) + sinon.stub(electron.shell, 'openExternal').rejects(new Error) const sendWarning = sinon.stub() return auth._launchNativeAuth(REDIRECT_URL, sendWarning) .then(() => { - expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL, {}, sinon.match.func) + expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL) expect(sendWarning).to.be.calledWithMatch('warning', 'AUTH_COULD_NOT_LAUNCH_BROWSER', REDIRECT_URL) }) }) diff --git a/packages/server/test/unit/gui/dialog_spec.coffee b/packages/server/test/unit/gui/dialog_spec.coffee index 43a5d3eecdca..89133131770a 100644 --- a/packages/server/test/unit/gui/dialog_spec.coffee +++ b/packages/server/test/unit/gui/dialog_spec.coffee @@ -7,7 +7,9 @@ Windows = require("#{root}../lib/gui/windows") describe "gui/dialog", -> context ".show", -> beforeEach -> - @showOpenDialog = electron.dialog.showOpenDialog = sinon.stub() + @showOpenDialog = electron.dialog.showOpenDialog = sinon.stub().resolves({ + filePaths: [] + }) it "calls dialog.showOpenDialog with args", -> dialog.show() @@ -16,13 +18,13 @@ describe "gui/dialog", -> }) it "resolves with first path", -> - @showOpenDialog.yields(["foo", "bar"]) + @showOpenDialog.resolves({ + filePaths: ["foo", "bar"] + }) dialog.show().then (ret) -> expect(ret).to.eq("foo") it "handles null paths", -> - @showOpenDialog.yields(null) - dialog.show().then (ret) -> expect(ret).to.eq(undefined) From c9008f552242b31c2e38e0060dd73a50c5e9d315 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Tue, 24 Sep 2019 12:23:13 -0400 Subject: [PATCH 2/5] Revert "node12.4.0-chrome76 => node12.0.0-chrome75" This reverts commit 3581e52708129e8def8531e6bca11b93c009e69c. --- circle.yml | 2 +- scripts/run-docker-local.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index ca875d9fe619..4843c03bd46f 100644 --- a/circle.yml +++ b/circle.yml @@ -23,7 +23,7 @@ executors: # the Docker image with Cypress dependencies and Chrome browser cy-doc: docker: - - image: cypress/browsers:node12.0.0-chrome73 + - image: cypress/browsers:node12.4.0-chrome76 environment: PLATFORM: linux diff --git a/scripts/run-docker-local.sh b/scripts/run-docker-local.sh index 71e5e7ff3aa3..13bfa2b3eafe 100755 --- a/scripts/run-docker-local.sh +++ b/scripts/run-docker-local.sh @@ -2,7 +2,7 @@ set e+x echo "This script should be run from cypress's root" -name=cypress/browsers:node12.0.0-chrome73 +name=cypress/browsers:node12.4.0-chrome76 echo "Pulling CI container $name" docker pull $name From 7028411ffd5a3b962a8f4b10d61ba3179bfab9e9 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Tue, 24 Sep 2019 12:23:14 -0400 Subject: [PATCH 3/5] Revert "fix tests for electron downgrade" This reverts commit d2a00751ef259712e36df5fe799ab93daf3c66f3. --- packages/server/__snapshots__/8_reporters_spec.coffee.js | 1 - packages/server/test/integration/cypress_spec.coffee | 6 +++--- packages/server/test/unit/browsers/electron_spec.coffee | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/server/__snapshots__/8_reporters_spec.coffee.js b/packages/server/__snapshots__/8_reporters_spec.coffee.js index 65b84dfe8b43..8738b651edca 100644 --- a/packages/server/__snapshots__/8_reporters_spec.coffee.js +++ b/packages/server/__snapshots__/8_reporters_spec.coffee.js @@ -697,7 +697,6 @@ Error: this reporter threw an error at stack trace line at stack trace line at stack trace line - at stack trace line Learn more at https://on.cypress.io/reporters diff --git a/packages/server/test/integration/cypress_spec.coffee b/packages/server/test/integration/cypress_spec.coffee index 359a280ce380..e4bd5a84d426 100644 --- a/packages/server/test/integration/cypress_spec.coffee +++ b/packages/server/test/integration/cypress_spec.coffee @@ -774,12 +774,12 @@ describe "lib/cypress", -> debugger: { on: sinon.stub() attach: sinon.stub() - sendCommand: sinon.stub().callsArg(2) + sendCommand: sinon.stub().resolves() } setUserAgent: sinon.stub() session: { - clearCache: sinon.stub().yieldsAsync() - setProxy: sinon.stub().yieldsAsync() + clearCache: sinon.stub().resolves() + setProxy: sinon.stub().resolves() setUserAgent: sinon.stub() } } diff --git a/packages/server/test/unit/browsers/electron_spec.coffee b/packages/server/test/unit/browsers/electron_spec.coffee index 9b1b0492239e..551d7228e8f9 100644 --- a/packages/server/test/unit/browsers/electron_spec.coffee +++ b/packages/server/test/unit/browsers/electron_spec.coffee @@ -348,7 +348,7 @@ describe "lib/browsers/electron", -> it "sets proxy rules for webContents", -> webContents = { session: { - setProxy: sinon.stub().callsArg(1) + setProxy: sinon.stub().resolves() } } @@ -366,6 +366,8 @@ describe "lib/browsers/electron", -> @sendCommand.throws() .withArgs('Browser.getVersion').resolves() + electron._attachDebugger(@win.webContents) + @onRequest = electron._getAutomation(@win).onRequest describe "get:cookies", -> From 720cfe605e4a299c39235e8ba6b2c51926367772 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Tue, 24 Sep 2019 12:23:50 -0400 Subject: [PATCH 4/5] electron@6.0.10 --- packages/electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/electron/package.json b/packages/electron/package.json index a4a1b21bbac0..c5535d0a3384 100644 --- a/packages/electron/package.json +++ b/packages/electron/package.json @@ -26,7 +26,7 @@ "minimist": "1.2.0" }, "devDependencies": { - "electron": "5.0.10", + "electron": "6.0.10", "mocha": "3.5.3" }, "files": [ From 592cb0a6e2021a04528c6ea49be784916f5437d5 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Fri, 27 Sep 2019 10:54:44 -0400 Subject: [PATCH 5/5] appveyor pls