This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(debugger): make element explorer work with node 0.12.0
Node has changed its debugger significantly in 0.12.0, and these changes are necessary to get it to work now. Specifically here are the key points to take note: * Before, the process continues running after `process._debugProcess(pid);` is called, but now, the process stops. > To over come this, the call to `process._debugProcess(pid)` is moved from protractor into the debugger client. Secondly, because the process stops after the call, we call `reqContinue` once the debugger connection is established, so that protractor continues into the first break point (for backwards compatibility, we added an extra empty webdriver command so that in earlier versions of node, protractor doesn't go past the first break point from the reqContinue). * Before repl provides '(foobar\n)' when an user inputs 'foobar'. Now it is just 'foobar\n'. > We will parse and strip away both the parenthesis and '\n' to support all versions of node. * Additionally (non-related to node 0.12.0), this change makes debugger processes fail fast if the port is taken.
- Loading branch information
Showing
6 changed files
with
146 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var baseDebugger = require('_debugger'); | ||
|
||
/** | ||
* Create a debugger client and attach to a running protractor process. | ||
* Set a break point at webdriver executor. | ||
* @param {number} pid Pid of the process to attach the debugger to. | ||
* @param {number=} opt_port Port to set up the debugger connection over. | ||
* @return {!baseDebugger.Client} The connected debugger client. | ||
*/ | ||
exports.attachDebugger = function(pid, opt_port) { | ||
var client = new baseDebugger.Client(); | ||
var port = opt_port || process.debugPort; | ||
|
||
// Call this private function instead of sending SIGUSR1 because Windows. | ||
process._debugProcess(pid); | ||
|
||
client.once('ready', function() { | ||
client.setBreakpoint({ | ||
type: 'scriptRegExp', | ||
target: '.*executors\.js', //jshint ignore:line | ||
line: 37 | ||
}, function() { | ||
client.reqContinue(function() { | ||
// Intentionally blank. | ||
}); | ||
}); | ||
}); | ||
|
||
// Connect to debugger on port with retry 200ms apart. | ||
var connectWithRetry = function(attempts) { | ||
client.connect(port, 'localhost') | ||
.on('error', function(e) { | ||
if (attempts === 1) { | ||
throw e; | ||
} else { | ||
setTimeout(function() { | ||
connectWithRetry(attempts - 1); | ||
}, 200); | ||
} | ||
}); | ||
}; | ||
connectWithRetry(10); | ||
|
||
return client; | ||
}; | ||
|
||
/** | ||
* Trim excess symbols from the repl command so that it is consistent with | ||
* the user input. | ||
* @param {string} cmd Cmd provided by the repl server. | ||
* @return {string} The trimmed cmd. | ||
*/ | ||
exports.trimReplCmd = function(cmd) { | ||
// Given user input 'foobar', some versions of node provide '(foobar\n)', | ||
// while other versions of node provide 'foobar\n'. | ||
if (cmd.length >= 2 && cmd[0] === '(' && cmd[cmd.length - 1] === ')') { | ||
cmd = cmd.substring(1, cmd.length - 1); | ||
} | ||
return cmd.slice(0, cmd.length - 1); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters