logtrap
v0.0.1
Published
Clean up lingering brew dependencies
Downloads
22
Readme
logtrap
Capture stdout/stderr for testing purposes
Why?
To test applications where the output matters
Usage
Install logtrap
$ npm install logtrap
Setup tests that need to capture output
require 'mocha'
{ expect } = require 'chai' # or your favorite assertion tool
{ stdoutTrap, stderrTrap } = require 'logtrap'
# Some function that outputs to stdout
logger = (type, msg) -> console[type] "#{type}: #{msg}"
# Test
describe 'Capture outputs', ->
it 'should suppress stderr and capture instead', ->
good = stdoutTrap -> logger 'log', "All systems go!"
expect(good).to.equal "log: All systems go!\n"
it 'should suppress stderr and capture instead', ->
bad = stderrTrap -> logger 'error', "It's a trap"
expect(bad).to.equal "error: It's a trap\n"
View pretty test results
# Test outputs
Capture console.log
✓ should suppress stderr and capture instead
✓ should suppress stderr and capture instead
# Note that the test results are not polluted with the output logs
Notes
- [^.^]
License
Logtrap is released under the MIT License.