Skip to content

Commit

Permalink
Added support for node debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
simondean committed Nov 8, 2013
1 parent 6af0002 commit f8da18a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
8 changes: 8 additions & 0 deletions bin/myriad-cucumber
Expand Up @@ -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;

Expand All @@ -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._
};

Expand Down
46 changes: 35 additions & 11 deletions lib/myriad_cucumber.js
Expand Up @@ -150,19 +150,15 @@ 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 = [];

Async.eachLimit(
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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f8da18a

Please sign in to comment.