Pārlūkot izejas kodu

Allow the use of the PhantomJS remote debugger

This commit adds the '--debugger <port>' 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.
Solly Ross 10 gadi atpakaļ
vecāks
revīzija
07f514d887
2 mainītis faili ar 15 papildinājumiem un 2 dzēšanām
  1. 13 1
      tests/run_from_console.casper.js
  2. 2 1
      tests/run_from_console.js

+ 13 - 1
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);

+ 2 - 1
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 <port>', '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('');