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 1 commit
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
20 changes: 11 additions & 9 deletions packages/desktop-gui/src/lib/ipc-bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ const addMsg = (id, event, fn) => {
}
}

const nullifyUnserializableValues = (obj) => {
// nullify values that cannot be cloned
// https://github.com/cypress-io/cypress/issues/6750
return _.cloneDeepWith(obj, (val) => {
if (_.isFunction(val) || _.isElement(val)) {
return null
}
})
}

const removeMsgsByEvent = (event) => {
msgs = _.omitBy(msgs, (msg) => {
return msg.event === event
Expand Down Expand Up @@ -96,15 +106,7 @@ const ipcBus = (...args) => {
}
}

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

// pass in request, id, and remaining args
ipc.send(...['request', id].concat(args))
Expand Down
8 changes: 4 additions & 4 deletions packages/server/lib/gui/events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ chromePolicyCheck = require("../util/chrome_policy_check")
browsers = require("../browsers")
konfig = require("../konfig")

removeUnserializableValues = (obj) =>
## remove values that cannot be cloned
nullifyUnserializableValues = (obj) =>
## nullify 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
Expand All @@ -33,7 +33,7 @@ handleEvent = (options, bus, event, id, type, arg) ->

sendResponse = (originalData = {}) ->
try
data = removeUnserializableValues(originalData)
data = nullifyUnserializableValues(originalData)

debug("sending ipc data %o", { type, data, originalData })
event.sender.send("response", data)
Expand Down Expand Up @@ -327,7 +327,7 @@ handleEvent = (options, bus, event, id, type, arg) ->
throw new Error("No ipc event registered for: '#{type}'")

module.exports = {
removeUnserializableValues
nullifyUnserializableValues

handleEvent

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(events.removeUnserializableValues(@win))
assert.sendCalledWith(events.nullifyUnserializableValues(@win))

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