var fs = require('fs');
var path = require('path');
var tty = require('tty');
var expect = require('chai').expect;

var ttycolor = require('../..');
var outlog = path.join(__dirname, '..', '..', 'log', 'out.log');
var errlog = path.join(__dirname, '..', '..', 'log', 'err.log');

var stdout = {reader: null, writer: null}, stderr = {reader: null, writer: null};

describe('ttycolor:', function() {
  beforeEach(function(done) {
    stdout.writer = fs.createWriteStream(outlog, {flags: 'w'});
    stdout.writer.on('open', function(fd) {
      stdout.reader = fs.createReadStream(outlog, 'r');
      stdout.reader.on('open', function(fd) {
        done();
      });
    });
  });
  it('should export properties', function(done) {
    expect(ttycolor.ansi).to.be.a('function');
    expect(ttycolor.attributes).to.be.an('object');
    expect(ttycolor.background).to.be.an('object');
    expect(ttycolor.colors).to.be.an('array');
    expect(ttycolor.console).to.be.an('object');
    expect(ttycolor.foreground).to.be.an('object');
    expect(ttycolor.stringify).to.be.a('function');
    done();
  });
  it('should write to stream', function(done) {
    var input = 'value';
    function cb(value) {
      expect(value).to.be.a('string').that.equals(input);
      stdout.writer.end();
      done();
    }
    console.write({stream: stdout.writer, callback: cb}, input);
  });
  it('should print empty string with no arguments', function(done) {
    function cb(value) {
      expect(value).to.be.a('string').that.equals('');
      stdout.writer.end();
      done();
    }
    console.write({stream: stdout.writer, callback: cb});
  });
  it('should return vanilla string', function(done) {
    var input = 'value';
    var result = ttycolor.debug('%s', input);
    expect(result).to.be.a('string').that.equals(input);
    done();
  });
  it('should return vanilla number', function(done) {
    var input = 3.14;
    var result = ttycolor.debug('%s', input);
    expect(result).to.be.a('string').that.equals('' + input);
    done();
  });
  it('should return vanilla json', function(done) {
    var input = {message: 'json'};
    var result = ttycolor.debug('%j', input);
    expect(result).to.be.a('string').that.equals(JSON.stringify(input));
    done();
  });
})

@@ -315,16 +315,18 @@
 : null%7D,
+%0A 
  stderr 
@@ -357,16 +357,16 @@
  null%7D;%0A
-
 %0Adescrib
@@ -535,112 +535,8 @@
 ) %7B%0A
-      stdout.reader = fs.createReadStream(outlog, 'r');%0A      stdout.reader.on('open', function(fd) %7B%0A  
     
@@ -549,18 +549,8 @@
 ();%0A
-      %7D);%0A
     
@@ -848,32 +848,80 @@
 e.an('object');%0A
+    expect(ttycolor.debug).to.be.a('function');%0A
     expect(ttyco
@@ -1317,13 +1317,14 @@
 uld 
-print
+return
  emp
@@ -1374,39 +1374,47 @@
 ) %7B%0A    
-function cb(value) %7B%0A  
+var result = ttycolor.debug();%0A
     expe
@@ -1408,37 +1408,38 @@
 g();%0A    expect(
-value
+result
 ).to.be.a('strin
@@ -1467,106 +1467,13 @@
     
-  stdout.writer.end();%0A      done();%0A    %7D%0A    console.write(%7Bstream: stdout.writer, callback: cb%7D
+done(
 );%0A 

Update tests.