Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 71a8d94

Browse files
committed
To be squashed: Address comments and add some more docs
1 parent 5f79c6f commit 71a8d94

File tree

5 files changed

+52
-30
lines changed

5 files changed

+52
-30
lines changed

lib/breakpointhook.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
module.exports = function() {
22
return true;
33
};
4+
5+
/**
6+
* The reason this file exists is so that we can set a breakpoint via
7+
* script name, and then control when that breakpoint is set in
8+
* our library code by importing and calling this function. The
9+
* breakpoint will always be on line 2.
10+
*/

lib/browser.ts

+26-17
Original file line numberDiff line numberDiff line change
@@ -972,37 +972,46 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
972972
}
973973

974974
/**
975-
* Beta (unstable) enterRepl function for entering the repl loop from
976-
* any point in the control flow. Use browser.enterRepl() in your test.
975+
* See browser.explore().
976+
*/
977+
enterRepl(opt_debugPort?: number) {
978+
return this.explore(opt_debugPort);
979+
}
980+
981+
/**
982+
* Beta (unstable) explore function for entering the repl loop from
983+
* any point in the control flow. Use browser.explore() in your test.
977984
* Does not require changes to the command line (no need to add 'debug').
978985
* Note, if you are wrapping your own instance of Protractor, you must
979986
* expose globals 'browser' and 'protractor' for pause to work.
980987
*
981988
* @example
982989
* element(by.id('foo')).click();
983-
* browser.enterRepl();
990+
* browser.explore();
984991
* // Execution will stop before the next click action.
985992
* element(by.id('bar')).click();
986993
*
987994
* @param {number=} opt_debugPort Optional port to use for the debugging
988995
* process
989996
*/
990-
enterRepl(opt_debugPort?: number) {
997+
explore(opt_debugPort?: number) {
991998
let debuggerClientPath = __dirname + '/debugger/clients/explorer.js';
992-
let onStartFn = () => {
993-
logger.info();
994-
logger.info('------- Element Explorer -------');
995-
logger.info(
996-
'Starting WebDriver debugger in a child process. Element ' +
997-
'Explorer is still beta, please report issues at ' +
998-
'github.com/angular/protractor');
999-
logger.info();
1000-
logger.info('Type <tab> to see a list of locator strategies.');
1001-
logger.info('Use the `list` helper function to find elements by strategy:');
1002-
logger.info(' e.g., list(by.binding(\'\')) gets all bindings.');
999+
let onStartFn = (firstTime: boolean) => {
10031000
logger.info();
1001+
if (firstTime) {
1002+
logger.info('------- Element Explorer -------');
1003+
logger.info(
1004+
'Starting WebDriver debugger in a child process. Element ' +
1005+
'Explorer is still beta, please report issues at ' +
1006+
'github.com/angular/protractor');
1007+
logger.info();
1008+
logger.info('Type <tab> to see a list of locator strategies.');
1009+
logger.info('Use the `list` helper function to find elements by strategy:');
1010+
logger.info(' e.g., list(by.binding(\'\')) gets all bindings.');
1011+
logger.info();
1012+
}
10041013
};
1005-
this.debugHelper.init(debuggerClientPath, true, onStartFn, opt_debugPort);
1014+
this.debugHelper.initBlocking(debuggerClientPath, onStartFn, opt_debugPort);
10061015
}
10071016

10081017
/**
@@ -1043,6 +1052,6 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
10431052
logger.info();
10441053
}
10451054
};
1046-
this.debugHelper.init(debuggerClientPath, false, onStartFn, opt_debugPort);
1055+
this.debugHelper.init(debuggerClientPath, onStartFn, opt_debugPort);
10471056
}
10481057
}

lib/debugger.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,34 @@ export class DebugHelper {
2626

2727
constructor(private browserUnderDebug_: ProtractorBrowser) {}
2828

29+
30+
initBlocking(debuggerClientPath: string, onStartFn: Function, opt_debugPort?: number) {
31+
this.init_(debuggerClientPath, true, onStartFn, opt_debugPort);
32+
}
33+
34+
init(debuggerClientPath: string, onStartFn: Function, opt_debugPort?: number) {
35+
this.init_(debuggerClientPath, false, onStartFn, opt_debugPort);
36+
}
37+
2938
/**
3039
* 1) Set up helper functions for debugger clients to call on (e.g.
3140
* execute code, get autocompletion).
3241
* 2) Enter process into debugger mode. (i.e. process._debugProcess).
3342
* 3) Invoke the debugger client specified by debuggerClientPath.
3443
*
3544
* @param {string} debuggerClientPath Absolute path of debugger client to use.
36-
* @param {boolean} blockUntilExit Whether to block until process exit or resume immediately.
45+
* @param {boolean} blockUntilExit Whether to block the flow until process exit or resume
46+
* immediately.
3747
* @param {Function} onStartFn Function to call when the debugger starts. The
3848
* function takes a single parameter, which represents whether this is the
3949
* first time that the debugger is called.
40-
* @param {number=} opt_debugPort Optional port to u`se for the debugging
50+
* @param {number=} opt_debugPort Optional port to use for the debugging
4151
* process.
52+
*
53+
* @return {Promise} If blockUntilExit, a promise resolved when the debugger process
54+
* exits. Otherwise, resolved when the debugger process is ready to begin.
4255
*/
43-
init(
56+
init_(
4457
debuggerClientPath: string, blockUntilExit: boolean, onStartFn: Function,
4558
opt_debugPort?: number) {
4659
wdpromise.ControlFlow.prototype.getControlFlowText = function() {
@@ -83,7 +96,7 @@ export class DebugHelper {
8396

8497
// We run one flow.execute block for the debugging session. All
8598
// subcommands should be scheduled under this task.
86-
var executePromise = flow.execute(() => {
99+
let executePromise = flow.execute(() => {
87100
process['debugPort'] = opt_debugPort || process['debugPort'];
88101
this.validatePortAvailability_(process['debugPort']).then((firstTime: boolean) => {
89102
onStartFn(firstTime);
@@ -123,7 +136,7 @@ export class DebugHelper {
123136
// To be able to simulate callback/asynchronous code, we poll this object
124137
// whenever `breakpointHook` is called.
125138
this.dbgCodeExecutor = {
126-
execPromise_: null, // Promise pointing to currently executing command.
139+
execPromise_: undefined, // Promise pointing to currently executing command.
127140
execPromiseResult_: undefined, // Return value of promise.
128141
execPromiseError_: undefined, // Error from promise.
129142

lib/debugger/clients/wddebugger.js

-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ WdDebugger.prototype.initRepl_ = function() {
4242

4343
// We want the prompt to show up only after the controlflow text prints.
4444
this.dbgRepl.printControlFlow_(function() {
45-
// Backward compatibility: node version 0.8.14 has a number of built in
46-
// libraries for repl, and the keyword 'repl' clashes with our usage.
47-
// if (repl._builtinLibs && repl._builtinLibs.indexOf('repl') > -1) {
48-
// repl._builtinLibs.splice(repl._builtinLibs.indexOf('repl'), 1);
49-
// }
5045
self.replServer = repl.start({
5146
prompt: self.dbgRepl.prompt,
5247
input: process.stdin,

lib/debugger/modes/debuggerRepl.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ DebuggerRepl.prototype.stepEval = function(cmd, callback) {
8383
* @param {string} line Initial user entry
8484
* @param {function} callback
8585
*/
86-
DebuggerRepl.prototype.complete = function(line, callback) {
87-
console.log('calling debuggerrepl complete');
88-
86+
DebuggerRepl.prototype.complete = function(line, callback) {
8987
var suggestions = DBG_INITIAL_SUGGESTIONS.filter(function(suggestion) {
9088
return suggestion.indexOf(line) === 0;
9189
});

0 commit comments

Comments
 (0)