coffee

Test command line on nodejs

Coffee

Test command line on nodejs


## Install
 
$ npm install coffee -g

Coffee is useful to test command line in Mocha or other test frammework.

describe('cat', function() {
  it('should concat input', function(done) {
    var coffee = require('coffee');
    coffe.spawn('cat')
    .write('1')
    .write('2')
    .expect('stdout', '12')
    .expect('code', 0)
    .end(done);
  })
})

You can also use fork for spawning Node processes.

coffe.fork('/path/to/file.js', ['args '])
.expect('stdout', '12\n')
.expect('stderr', '34\n')
.expect('code', 0)
.end(done);

In file.js

console.log(12);
console.log(34);

Run command using child_process.spawn, then return Coffee instance.

Arguments see child_process.spawn

Run command using child_process.fork, then return Coffee instance.

Arguments see child_process.fork

Assertion object

Assert type with expected value, expected value can be string, regular expression, and array.

coffe.spawn('echo', ['abcdefg'])
.expect('stdout', 'abcdefg')
.expect('stdout', /^abc/)
.expect('stdout', ['abcdefg', /abc/])
.end(done);

Accept type: stdout, stderr, code

Write data to stdin, see example above.

Callback will be called after completing the assertion, the first argument is Error if throw exception.

Copyright (c) 2015 popomore. Licensed under the MIT license.