Giter VIP home page Giter VIP logo

coffee's Introduction

Coffee

Test command line on Node.js.


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

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.

coffee's People

Contributors

alsotang avatar fengmk2 avatar hotoo avatar nightink avatar popomore avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.