Skip to content

DavidCai1111/coffee

 
 

Repository files navigation

Coffee

Test command line on nodejs


NPM version Build Status codecov.io NPM downloads

Install

$ npm install coffee -g

Usage

Coffee is useful for test command line in test frammework (like Mocha).

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

You can also use fork for spawning Node processes.

coffee.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.error(34);

API

coffee.spawn

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

Arguments see child_process.spawn

coffee.fork

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

Arguments see child_process.fork

Coffee

Assertion object

coffee.expect(type, expected)

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

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

Accept type: stdout, stderr, code, error

coffee.write(data)

Write data to stdin, see example above.

coffee.end(callback)

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

coffee.debug()

Write data to process.stdout and process.stderr for debug

LISENCE

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

About

Test command line on nodejs

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%