Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation warnings from Electron 8 upgrade #6753

Merged
merged 5 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/desktop-gui/cypress/integration/ipc_bus_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import ipcBus from '../../src/lib/ipc-bus'

const RANDOM_NUMBER = 0.5

describe('IPC bus', () => {
beforeEach(() => {
cy.stub(Math, 'random').returns(RANDOM_NUMBER)
cy.stub(window.ipc, 'on').returns()
cy.stub(window.ipc, 'send').returns()
})

it('sends event as expected', () => {
ipcBus('foo:bar', 'baz', 'quux')

expect(window.ipc.send).to.be.calledWith('request', RANDOM_NUMBER, 'foo:bar', 'baz', 'quux')
flotwig marked this conversation as resolved.
Show resolved Hide resolved
})

it('removes functions & elements from the args', () => {
const obj = {
el: document.querySelector('div'),
fn: () => {},
str: 'foo',
}

ipcBus('bar', obj)

expect(window.ipc.send).to.be.calledWith('request', RANDOM_NUMBER, 'bar', {
flotwig marked this conversation as resolved.
Show resolved Hide resolved
el: null,
fn: null,
str: 'foo',
})
})
})
10 changes: 10 additions & 0 deletions packages/desktop-gui/src/lib/ipc-bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ const ipcBus = (...args) => {
}
}

// remove nodes that cannot be cloned
// https://github.com/cypress-io/cypress/issues/6750
args = args.map((arg) => {
flotwig marked this conversation as resolved.
Show resolved Hide resolved
return _.cloneDeepWith(arg, (val) => {
if (_.isFunction(val) || _.isElement(val)) {
return null
}
})
})

// pass in request, id, and remaining args
ipc.send(...['request', id].concat(args))

Expand Down
6 changes: 6 additions & 0 deletions packages/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ require && require.extensions && delete require.extensions['.coffee.md']
// https://github.com/electron/electron/blob/master/docs/api/process.md#processenablepromiseapis
process.enablePromiseAPIs = process.env.CYPRESS_INTERNAL_ENV !== 'production'

// don't show any electron deprecation warnings in prod
process.noDeprecation = process.env.CYPRESS_INTERNAL_ENV === 'production'

// always show stack traces for Electron deprecation warnings
process.traceDeprecation = true

require('./lib/util/suppress_unauthorized_warning').suppress()

module.exports = require('./lib/cypress').start(process.argv)
17 changes: 14 additions & 3 deletions packages/server/lib/gui/events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ chromePolicyCheck = require("../util/chrome_policy_check")
browsers = require("../browsers")
konfig = require("../konfig")

removeUnserializableValues = (obj) =>
## remove values that cannot be cloned
## https://github.com/cypress-io/cypress/issues/6750
_.cloneDeepWith obj, (val) =>
if _.isFunction(val)
bahmutov marked this conversation as resolved.
Show resolved Hide resolved
return null

handleEvent = (options, bus, event, id, type, arg) ->
debug("got request for event: %s, %o", type, arg)

sendResponse = (data = {}) ->
sendResponse = (originalData = {}) ->
try
debug("sending ipc data %o", {type: type, data: data})
data = removeUnserializableValues(originalData)

debug("sending ipc data %o", { type, data, originalData })
event.sender.send("response", data)

sendErr = (err) ->
Expand Down Expand Up @@ -318,7 +327,9 @@ handleEvent = (options, bus, event, id, type, arg) ->
throw new Error("No ipc event registered for: '#{type}'")

module.exports = {
handleEvent: handleEvent
removeUnserializableValues

handleEvent

stop: ->
ipc.removeAllListeners()
Expand Down
3 changes: 3 additions & 0 deletions packages/server/lib/modes/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { app } = require('electron')
const image = require('electron').nativeImage
const Promise = require('bluebird')
const cyIcons = require('@cypress/icons')
const electronApp = require('../util/electron-app')
const savedState = require('../saved_state')
const menu = require('../gui/menu')
const Events = require('../gui/events')
Expand Down Expand Up @@ -118,6 +119,8 @@ module.exports = {
})
}

electronApp.allowRendererProcessReuse()

return Promise.any([
waitForReady(),
Promise.delay(500),
Expand Down
14 changes: 12 additions & 2 deletions packages/server/lib/util/electron-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ const scale = () => {
}
}

const allowRendererProcessReuse = () => {
const { app } = require('electron')

// @see https://github.com/electron/electron/issues/18397
// NOTE: in Electron 9, this can be removed, since it will be the new default
app.allowRendererProcessReuse = true
}

// NOTE: this function is only called in run mode
const waitForReady = () => {
const debug = require('debug')('cypress:server:electron-app')

const Promise = require('bluebird')
const { app } = require('electron')

// @see https://github.com/electron/electron/issues/18397
app.allowRendererProcessReuse = true
allowRendererProcessReuse()

// electron >= 5.0.0 will exit the app if all browserwindows are closed,
// this is obviously undesirable in run mode
Expand All @@ -42,6 +50,8 @@ const isRunning = () => {
}

module.exports = {
allowRendererProcessReuse,

scale,

waitForReady,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/unit/gui/events_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe "lib/gui/events", ->
it "calls Windows#open with args and resolves with return of Windows.open", ->
@handleEvent("window:open", {type: "INDEX"})
.then (assert) =>
assert.sendCalledWith(@win)
assert.sendCalledWith(events.removeUnserializableValues(@win))

it "catches errors", ->
err = new Error("foo")
Expand Down