New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mocha-streambuffer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha-streambuffer

A small utility to capture console output in mocha tests

latest
npmnpm
Version
1.0.24
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

mocha-streambuffer

A small utility to assert console output in mocha tests

Usage

const StreamBuffer = require('mocha-streambuffer');
const assert = require('assert');

var stdout;

describe('StreamBuffer', function()
{
  before(function()
  {
    stdout = new StreamBuffer(process.stdout, true).hook();
  });
  
  beforeEach(function()
  {
    stdout.clean();
  });
  
  after(function()
  {
    stdout.unhook();
  });

  describe('Catch', function()
  {
    it('should catch stdout', function()
    {
      console.log('ping');
      assert.equal(stdout.buffer(), 'ping\n');
    });
  });

  describe('Includes', function()
  {
    it('should include ping', function()
    {
      console.log('ping');
      assert.ok(stdout.buffer().includes('ping'));
    });

  });

});

StreamBuffer(stream, [verbose=true])

stream: The stream to buffer
verbose: Whether to still write to the stream

StreamBuffer.hook() => this
Starts buffering

StreamBuffer.unhook() => this
Stops buffering

StreamBuffer.buffer() => String
Returns the buffer

StreamBuffer.clean() => String
Resets the buffer and returns it

Credits

jjm for this excellent post on stackoverflow.

Keywords

mocha

FAQs

Package last updated on 03 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts