logtrap

0.0.1 • Public • Published

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 
  { stdoutTrapstderrTrap } = 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.

Readme

Keywords

none

Package Sidebar

Install

npm i logtrap

Weekly Downloads

3

Version

0.0.1

License

MIT

Last publish

Collaborators

  • geekjuice