From 1bcd031ba2f3b23f325c449e7a2b86ec5fa0427a Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Thu, 28 May 2015 15:07:43 -0400 Subject: [PATCH] Allow the use of the PhantomJS remote debugger This commit adds the '--debugger ' option, which triggers the PhantomJS remote debugger. The initial output of the terminal when running the debugger gives more information on how to use it. --- tests/run_from_console.casper.js | 14 +++++++++++++- tests/run_from_console.js | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/run_from_console.casper.js b/tests/run_from_console.casper.js index 57ed2be..6a738a3 100644 --- a/tests/run_from_console.casper.js +++ b/tests/run_from_console.casper.js @@ -15,7 +15,19 @@ var casper_opts = { } }; -var provide_emitter = function(file_paths) { +var provide_emitter = function(file_paths, debug_port) { + if (debug_port) { + casper_opts.child['remote-debugger-port'] = debug_port; + var debug_url = ('https://localhost:' + debug_port + + '/webkit/inspector/inspector.html?page='); + console.info('[remote-debugger] Navigate to ' + debug_url + '1 and ' + + 'run `__run();` in the console to continue loading.' + + '\n[remote-debugger] Navigate to ' + debug_url + '2 to ' + + 'view the actual page source.\n' + + '[remote-debugger] Use the `debugger;` statement to ' + + 'trigger an initial breakpoint.'); + } + var spooky = new Spooky(casper_opts, function(err) { if (err) { if (err.stack) console.warn(err.stack); diff --git a/tests/run_from_console.js b/tests/run_from_console.js index 2a5bb70..f5c5bb4 100755 --- a/tests/run_from_console.js +++ b/tests/run_from_console.js @@ -20,6 +20,7 @@ program .option('--output-html', 'Instead of running the tests, just output the generated HTML source to STDOUT (should be used with .js tests)') .option('-d, --debug', 'Show debug output (the "console" event) from the provider') .option('-r, --relative', 'Use relative paths in the generated HTML file') + .option('--debugger ', 'Enable the remote debugger for CasperJS') .parse(process.argv); if (program.tests.length === 0) { @@ -202,7 +203,7 @@ if (!program.outputHtml && !program.generateHtml) { .write("\n"); //console.log("Running tests %s using provider %s", program.tests.join(', '), prov.name); - var provider = prov.provide_emitter(file_paths); + var provider = prov.provide_emitter(file_paths, program.debugger); provider.on('test_ready', function(test_json) { console.log('');