From f8da18a2f7e830a07f13b24ed8df76b8afaa6981 Mon Sep 17 00:00:00 2001 From: Simon Dean Date: Fri, 8 Nov 2013 23:26:51 +0000 Subject: [PATCH] Added support for node debugging --- bin/myriad-cucumber | 8 ++++++++ lib/myriad_cucumber.js | 46 ++++++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/bin/myriad-cucumber b/bin/myriad-cucumber index cd00ae1..7191b76 100755 --- a/bin/myriad-cucumber +++ b/bin/myriad-cucumber @@ -51,6 +51,12 @@ var optimist = Optimist boolean: true, default: false, describe: 'Enables cucumber\'s dry run mode' + }) + .options('debug', { + describe: 'Starts cucumber workers in debug mode. Pass a number to set the port the first worker should listen on. Subsequent workers will increment the port number. Default debug port is the node.js standard of 5858' + }) + .options('debug-brk', { + describe: 'Starts cucumber workers in debug mode and breaks on the first line. Accepts an optional port number like --debug' }); var argv = optimist.argv; @@ -66,6 +72,8 @@ else { localPackage: argv['local-package'], workers: argv.workers, dryRun: argv['dry-run'], + debug: argv.debug, + debugBrk: argv['debug-brk'], features: argv._ }; diff --git a/lib/myriad_cucumber.js b/lib/myriad_cucumber.js index 01107d0..a93a7d1 100644 --- a/lib/myriad_cucumber.js +++ b/lib/myriad_cucumber.js @@ -150,8 +150,6 @@ MyriadCucumber.prototype._executeFeaturesOnMyriadServer = function(options, call Debug('Found ' + tasks.length + ' tasks to execute'); Debug('Execution will be limited to ' + options.workers + ' workers'); - var workerCount = 0; - var firstReport = true; var workers = []; @@ -159,10 +157,8 @@ MyriadCucumber.prototype._executeFeaturesOnMyriadServer = function(options, call tasks, options.workers, function(task, callback) { - var workerIndex = workerCount++; - var worker = new Worker({ - workerIndex: workerIndex, + workerIndex: task.workerIndex, myriadServerUrl: options.myriadServerUrl, taskOptions: task.options, featurePath: task.featurePath, @@ -237,26 +233,54 @@ MyriadCucumber.prototype._executeFeaturesOnMyriadServer = function(options, call MyriadCucumber.prototype._getWorkerTasks = function(options, callback) { var tasks = []; + var workerCount = 0; + var debugArgName; + var firstDebugPort; + + if (options.debug) { + Debug('Enabling node debug mode') + debugArgName = '--debug'; + firstDebugPort = options.debug; + } + else if (options.debugBrk) { + Debug('Enabling node debug mode, breaking on first line') + debugArgName = '--debug-brk'; + firstDebugPort = options.debugBrk; + } - var extraArgs = []; - - if (options.dryRun) { - extraArgs.push('--dry-run'); + if (debugArgName) { + if (typeof firstDebugPort !== 'number') { + firstDebugPort = 5858; + } + Debug('Debug ports starting from ' + firstDebugPort); } options.featurePaths.forEach(function(featurePath) { Object.keys(options.profiles).forEach(function(profileName) { + var workerIndex = workerCount++; var profile = options.profiles[profileName]; - + var args = profile.args.slice(); var env = profile.env || {}; + + if (debugArgName) { + args.unshift(debugArgName + '=' + (firstDebugPort + workerIndex)); + } + + if (options.dryRun) { + args.push('--dry-run'); + } + + args.push(featurePath); + env.MYRIAD_CUCUMBER_PROFILE = profileName; var task = { + workerIndex: workerIndex, options: { package: options.package, localPackage: options.localPackage, bin: profile.bin, - args: profile.args.concat(extraArgs, [featurePath]), + args: args, env: env }, profileName: profileName,