coffee
Test command line on nodejs
Last updated 8 years ago by atian25 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install coffee 
SYNC missed versions from official npm registry.

Coffee

Test command line on Node.js.


NPM version Build Status codecov.io NPM downloads

Install

$ npm i coffee --save

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);

Support multiple process coverage with istanbul

Coffee will detect istanbul automatically, and generate coverage-{processId}.json, you should generate reporter by istanbul report.

$ rm -rf coverage
$ istanbul cover --report none --print none node_modules/mocha/bin/_mocha -- -R spec -t 5000
$ istanbul report text-summary json lcov
=============================== Coverage summary ===============================
State## ments   : 98.2% ( 109/111 )
Branches     : 97.37% ( 37/38 )
Functions    : 100% ( 20/20 )
Lines        : 98.18% ( 108/110 )
================================================================================

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.notExpect(type, expected)

The opposite assertion of expect.

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(level)

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

level can be

  • 0 (default): pipe stdout + stderr
  • 1: pipe stdout
  • 2: pipe stderr
  • false: disable

Alternative you can use COFFEE_DEBUG env.

coffee.coverage()

If you set false, coffee will not generate coverage.json, default: true.

LISENCE

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

Current Tags

  • 5.5.1                                ...           latest (3 years ago)
  • 3.3.3                                ...           latest-3 (8 years ago)
  • 4.2.1                                ...           latest-4 (8 years ago)

40 Versions

  • 5.5.1                                ...           3 years ago
  • 5.5.0                                ...           4 years ago
  • 5.4.0                                ...           7 years ago
  • 5.3.0                                ...           7 years ago
  • 5.2.2                                ...           7 years ago
  • 5.2.1                                ...           8 years ago
  • 5.2.0                                ...           8 years ago
  • 5.1.1                                ...           8 years ago
  • 4.2.1                                ...           8 years ago
  • 3.3.3                                ...           8 years ago
  • 5.1.0                                ...           8 years ago
  • 5.0.1                                ...           8 years ago
  • 4.2.0                                ...           8 years ago
  • 4.1.0                                ...           9 years ago
  • 4.0.1                                ...           9 years ago
  • 4.0.0                                ...           9 years ago
  • 3.3.2                                ...           10 years ago
  • 3.3.1                                ...           10 years ago
  • 3.3.0                                ...           10 years ago
  • 3.2.5                                ...           10 years ago
  • 3.2.4                                ...           10 years ago
  • 3.2.3                                ...           10 years ago
  • 3.2.2                                ...           10 years ago
  • 3.2.1                                ...           11 years ago
  • 3.2.0                                ...           11 years ago
  • 3.1.1                                ...           11 years ago
  • 3.1.0                                ...           11 years ago
  • 3.0.3                                ...           11 years ago
  • 3.0.2                                ...           11 years ago
  • 3.0.1                                ...           11 years ago
  • 3.0.0                                ...           11 years ago
  • 2.1.0                                ...           11 years ago
  • 2.0.0                                ...           11 years ago
  • 1.3.1                                ...           11 years ago
  • 1.3.0                                ...           11 years ago
  • 1.2.0                                ...           11 years ago
  • 1.1.0                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Downloads
Total 132
Today 0
This Week 0
This Month 53
Last Day 0
Last Week 0
Last Month 39
Dependencies (2)
Dev Dependencies (8)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE