Make the subcommand tests a bit more robust
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Itay Neeman · committed by TJ Holowaychuk · parent 2454486 · Browse files · 1 file·+25 added−14 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+25 added−14 removed
- tests:+25 added−14 removed
Provenance
- Commit
ba74d56- Tree
cd0ff89- Author
Itay Neeman <itay@neeman.net>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
2454486
1 file changed+25 added−14 removed
modified:test/test.options.commands.js+25 added-14 removed
9 unmodified lines10111213141516171819202122232425232627282930313233343235363738394 unmodified lines444546474849504647515253545556515257585960616256576364656667606168697071727365667475767778697079808182838485868711 unmodified lines9 unmodified lines .option('-C, --chdir <path>', 'change the working directory') .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf') .option('-T, --no-tests', 'ignore test hook')
var envValue = "";var cmdValue = "";
program .command('setup [env]') .description('run setup commands for all envs') .option("-s, --setup_mode [mode]", "Which setup mode to use") .option("-o, --host [host]", "Host to use") .action(function(env, options){ var mode = options.setup_mode || "normal"; env = env || 'all'; env.should.equal('env1'); envValue = env; });
program .command('exec <cmd>') .description('execute the given remote cmd') .option("-e, --exec_mode <mode>", "Which exec mode to use") .option("-t, --target [target]", "Target to use") .action(function(cmd, options){ cmd.should.equal('exec1'); cmdValue = cmd; });
program .command('*')4 unmodified linesprogram.parse(['node', 'test', '--config', 'conf']);program.config.should.equal("conf");program.commands[0].should.not.have.property.setup_mode;program.commands[1].should.not.have.property.exec_mode;envValue.should.be.null;cmdValue.should.be.null;
program.parse(['node', 'test', '--config', 'conf', 'setup', '--setup_mode', 'mode3', 'env1']);program.config.should.equal("conf");program.parse(['node', 'test', '--config', 'conf1', 'setup', '--setup_mode', 'mode3', 'env1']);program.config.should.equal("conf1");program.commands[0].setup_mode.should.equal("mode3");program.commands[0].should.not.have.property.host;envValue.should.equal("env1");
program.parse(['node', 'test', '--config', 'conf', 'setup', '--setup_mode', 'mode3', '-o', 'host1', 'env1']);program.config.should.equal("conf");program.parse(['node', 'test', '--config', 'conf2', 'setup', '--setup_mode', 'mode3', '-o', 'host1', 'env2']);program.config.should.equal("conf2");program.commands[0].setup_mode.should.equal("mode3");program.commands[0].host.should.equal("host1");envValue.should.equal("env2");
program.parse(['node', 'test', '--config', 'conf', 'setup', '-s', 'mode4', 'env1']);program.config.should.equal("conf");program.parse(['node', 'test', '--config', 'conf3', 'setup', '-s', 'mode4', 'env3']);program.config.should.equal("conf3");program.commands[0].setup_mode.should.equal("mode4");envValue.should.equal("env3");
program.parse(['node', 'test', '--config', 'conf', 'exec', '--exec_mode', 'mode1', 'exec1']);program.config.should.equal("conf");program.parse(['node', 'test', '--config', 'conf4', 'exec', '--exec_mode', 'mode1', 'exec1']);program.config.should.equal("conf4");program.commands[1].exec_mode.should.equal("mode1");program.commands[1].should.not.have.property.target;cmdValue.should.equal("exec1");
program.parse(['node', 'test', '--config', 'conf', 'exec', '-e', 'mode2', 'exec1']);program.config.should.equal("conf");program.parse(['node', 'test', '--config', 'conf5', 'exec', '-e', 'mode2', 'exec2']);program.config.should.equal("conf5");program.commands[1].exec_mode.should.equal("mode2");cmdValue.should.equal("exec2");
program.parse(['node', 'test', '--config', 'conf', 'exec', '--target', 'target1', '-e', 'mode2', 'exec1']);program.config.should.equal("conf");program.parse(['node', 'test', '--config', 'conf6', 'exec', '--target', 'target1', '-e', 'mode2', 'exec3']);program.config.should.equal("conf6");program.commands[1].exec_mode.should.equal("mode2");program.commands[1].target.should.equal("target1");cmdValue.should.equal("exec3");
// Make sure we still catch errors with required values for optionsvar exceptionOccurred = false;var oldProcessExit = process.exit;11 unmodified lines