-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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(debugger): fix issue where output does not display circular dep and ... #1889
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
var util = require('util'); | ||
var url = require('url'); | ||
var webdriver = require('selenium-webdriver'); | ||
var helper = require('./util'); | ||
|
@@ -698,14 +699,7 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort) | |
self.execPromiseResult_ = self.execPromiseError_ = undefined; | ||
|
||
self.execPromise_ = self.execPromise_. | ||
then(function() { | ||
var result = execFn_(); | ||
if (webdriver.promise.isPromise(result)) { | ||
return result.then(function(val) {return val;}); | ||
} else { | ||
return result; | ||
} | ||
}).then(function(result) { | ||
then(execFn_).then(function(result) { | ||
self.execPromiseResult_ = result; | ||
}, function(err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the reason for this in the past? It doesn't appear to do anything There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.execPromiseError_ = err; | ||
|
@@ -720,22 +714,42 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort) | |
}, | ||
|
||
// Execute a piece of code. | ||
// Result is a string representation of the evaluation. | ||
execute: function(code) { | ||
var execFn_ = function() { | ||
// Run code through vm so that we can maintain a local scope which is | ||
// isolated from the rest of the execution. | ||
return vm_.runInThisContext(code); | ||
var res = vm_.runInThisContext(code); | ||
if (!webdriver.promise.isPromise(res)) { | ||
res = webdriver.promise.fulfilled(res); | ||
} | ||
|
||
return res.then(function(res) { | ||
if (res === undefined) { | ||
return undefined; | ||
} else { | ||
// The '' forces res to be expanded into a string instead of just | ||
// '[Object]'. Then we remove the extra space caused by the '' using | ||
// substring. | ||
return util.format.apply(this, ['', res]).substring(1); | ||
} | ||
}); | ||
}; | ||
this.execute_(execFn_); | ||
}, | ||
|
||
// Autocomplete for a line. | ||
// Result is a JSON representation of the autocomplete response. | ||
complete: function(line) { | ||
var self = this; | ||
var execFn_ = function() { | ||
var deferred = webdriver.promise.defer(); | ||
self.replServer_.complete(line, function(err, res) { | ||
deferred.fulfill(res, err); | ||
if (err) { | ||
deferred.reject(err); | ||
} else { | ||
deferred.fulfill(JSON.stringify(res)); | ||
} | ||
}); | ||
return deferred; | ||
}; | ||
|
@@ -756,8 +770,7 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort) | |
if (this.execPromiseError_) { | ||
throw this.execPromiseError_; | ||
} | ||
|
||
return JSON.stringify(this.execPromiseResult_); | ||
return this.execPromiseResult_; | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change? Do we need an extra log here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before I was using JSON.stringify to serialize the data between protractor and the commandRepl, which would parse the string. However, this was not good because you can't serialize functions and objects with circular dependencies.
The only way to stringify the full object mimic what
console.log
does, which is to useutil.format
(see https://github.com/joyent/node/blob/v0.12.0/lib/console.js#L55).So then, lastly, why I can't do
callback(err, res)
, but must instead doconsole.log(res); callback(err, undefined)
. It's because during callback, nodejs doesn't console.log the result, but will rather print the result as is.Here are some outputs if I do
callback(err, res)
: