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' require 'chai' # or your favorite assertion tool require 'logtrap' # Some function that outputs to stdout = consoletype": " # Test describe 'Capture outputs'-> it 'should suppress stderr and capture instead'-> good = stdoutTrap -> logger 'log'"All systems go!" expectgoodtoequal "log: All systems go!\n" it 'should suppress stderr and capture instead'-> bad = stderrTrap -> logger 'error'"It's a trap" expectbadtoequal "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.