Skip to content

how to test terminal commands in node

Lance Pollard edited this page Sep 24, 2012 · 2 revisions

Testing ARGV

To test terminal commands, you can mock out program.ARGV:

program = require('commander')
program
  .version('0.0.1')
  .option('-f, --foo', 'add some foo')
  .option('-b, --bar', 'add some bar')

argv = ['node', 'test', '--foo', '--', '--bar', 'baz'] # program.ARGV mock

program.parse(argv)

Testing STDIN

Testing STDOUT

Clone this wiki locally