How to use the test-console.stderr function in test-console

To help you get started, we’ve selected a few test-console examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jaridmargolin / inspect-process / test / index.js View on Github external
'use strict'

/* -----------------------------------------------------------------------------
 * dependencies
 * -------------------------------------------------------------------------- */

// core
const spawn = require('child_process').spawn
const path = require('path')
const net = require('net')

// 3rd party
const _ = require('lodash/fp')
const assert = require('chai').assert
const stdout = require('test-console').stdout
const stderr = require('test-console').stderr

// lib
const inspect = require('../lib/index')

/* -----------------------------------------------------------------------------
 * reusable
 * -------------------------------------------------------------------------- */

const executablePath = path.resolve(__dirname, '..', 'bin', 'inspect.js')
const fixturesPath = path.resolve(__dirname, 'fixtures')

const successPath = path.resolve(fixturesPath, 'success')
const errorPath = path.resolve(fixturesPath, 'error')
const exceptionPath = path.resolve(fixturesPath, 'exception')

/* -----------------------------------------------------------------------------
github kartikayg / StatusPage / logger-service / src / app.spec.js View on Github external
it ('should log error to console and file for logger() error call', function () {

      const inspect = testConsole.stderr.inspect();

      logger.error(new Error('test123'));
      inspect.restore();

      // check for console
      assert.isAtLeast(inspect.output.length, 1); // one console
      
      // its hard to check the exact error stack string, so doing a partial match
      assert.match(inspect.output[inspect.output.length - 1], /\[ERROR:logger-service\] - \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z test123 \n.*/);

      // check for file
      assert.isTrue(fs.existsSync(appLogFile));

      const lastLine = JSON.parse(getLastLine(appLogFile));

      assert.strictEqual(lastLine.level, 'error');
github jonathaneunice / iterm2-tab-set / test / test_util.js View on Github external
const assert = require('chai').assert
const _      = require('underscore')
const path   = require('path')
const process = require('process')
const fs     = require('fs');
const stdout = require("test-console").stdout;
const stderr = require("test-console").stderr;
const util = require('../util');
util.globalize(util);

describe('util', function() {

  describe('globalize', function(){
    it('should make functions globally available', function(){
      assert.isFunction(definedOr);
      assert.isFunction(padRight);
      assert.isFunction(maxLength);
      assert.isFunction(longest);
    })
  })

  describe('definedOr', function () {
    it('should return first value, if defined, else default', function () {
github yoshuawuyts / fax / test / index.js View on Github external
const stderr = require('test-console').stderr
const fax    = require('../lib/index')
const test   = require('tape')

const AssertionError = require('assert').AssertionError

test('fax() should throw on non-generator function', function(t) {
  t.plan(1)
  const app = fax()
  t.throws(app.use.bind(app, function(){}), /requires a generator function/)
})

test('app.use should chain middleware', function(t) {
  t.plan(1)
  const app = fax()
  var i = 0
github toajs / toa / test / index.js View on Github external
'use strict'

const fs = require('fs')
const net = require('net')
const tman = require('tman')
const http = require('http')
const assert = require('assert')
const Stream = require('stream')
const request = require('supertest')
const statuses = require('statuses')
const stderr = require('test-console').stderr
const Toa = require('..')

tman.suite('app', function () {
  tman.it('should work', function () {
    const app = new Toa()
    app.use(function () {
      assert.strictEqual(this.req, this.request.req)
      assert.strictEqual(this.req, this.response.req)
      assert.strictEqual(this.res, this.request.res)
      assert.strictEqual(this.res, this.response.res)
      assert.strictEqual(this.request, this.response.request)
      assert.strictEqual(this.response, this.request.response)
      this.body = 'ok'
    })

    return request(app.listen())
github brunch / brunch / test / _test_helper.js View on Github external
t.is(fs.readFileSync(path, 'utf8'), content);
  } catch (e) {
    t.fail(e.message);
  }
};

const fileDoesNotContain = (t, path, content) => {
  try {
    t.false(fs.readFileSync(path, 'utf8').includes(content));
  } catch (e) {
    t.fail(e.message);
  }
};

const _stdout = require('test-console').stdout;
const _stderr = require('test-console').stderr;
let _inspect, _inspectE;

const spyOnConsole = () => {
  _inspect = _stdout.inspect();
  _inspectE = _stderr.inspect();
};

const restoreConsole = () => {
  _inspect.restore();
  _inspect.output.forEach(line => process.stdout.write(line));
  _inspect = null;

  _inspectE.restore();
  _inspectE.output.forEach(line => process.stderr.write(line));
  _inspectE = null;
};