Skip to content

Commit

Permalink
respond to PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Mar 17, 2020
1 parent e34663c commit af408c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
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)

// 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)
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

0 comments on commit af408c7

Please sign in to comment.