'use strict';

var should = require('should');
var path = require('path');
var fs = require('fs');
var rewire = require('rewire');
var pngdefry = rewire('../lib/index');
var Magic = require('mmmagic').Magic;
var magic = new Magic();

describe('Index', function() {

  describe('#pngdefry()', function() {
    // it('should repair png success', function(done) {
    it('should repair png success', function() {
      // this.timeout(115000);
      // var input = path.join(__dirname, 'img', 'icon.png');
      // var output = path.join(__dirname, 'img', 'icon-new.png');

      // pngdefry(input, output, function(err) {
      //   if (err) {
      //     return;
      //   }
      //
      //   magic.detectFile(output, function(err, result) {
      //     if (err) {
      //       throw err;
      //     }
      //
      //     // result=>PNG image data, 60 x 60, 8-bit/color RGBA, non-interlaced
      //     result.should.match(/non-interlaced/);
      //     fs.unlinkSync(output);
      //     setTimeout(done, 110000);
      //   });
      // });
    });
  });

  describe('#getOutputDir()', function() {
    it('should return a path that not contain the file name', function() {
      var output = path.join('Users', 'forsigner', 'repos', 'icon-new.png');
      var ouputDir = pngdefry.__get__('getOutputDir')(output);
      ouputDir.should.equal(path.join('Users', 'forsigner', 'repos'));
    });
  });

  describe('#getOutputFilePath()', function() {
    it('should return a path that not contain the file name', function() {
      var input = path.join('Users', 'forsigner', 'repos', 'icon.png');
      var outputDir = path.join('Users', 'forsigner', 'repos');
      var suffix = '-new';
      var outputFilePath = pngdefry.__get__('getOutputFilePath')(input, outputDir, suffix);
      outputFilePath.should.equal(path.join('Users', 'forsigner', 'repos', 'icon-new.png'));
    });
  });
});

@@ -301,19 +301,16 @@
 () %7B%0A   
- //
  it('sho
@@ -356,95 +356,12 @@
  %7B%0A 
-   it('should repair png success', function() %7B%0A      // this.timeout(115000);%0A
     
-  //
  var
@@ -415,19 +415,16 @@
 );%0A     
- //
  var out
@@ -480,19 +480,16 @@
 ;%0A%0A     
- //
  pngdefr
@@ -526,19 +526,16 @@
  %7B%0A     
- //
    if (e
@@ -550,31 +550,28 @@
     
-//
     
- return
+throw err
 ;%0A     
- //
    %7D
@@ -577,27 +577,22 @@
 %7D%0A      
-//
 %0A     
- //
    magic
@@ -636,27 +636,24 @@
 ult) %7B%0A     
- //
      if (err
@@ -657,27 +657,24 @@
 err) %7B%0A     
- //
        throw
@@ -689,23 +689,20 @@
     
-//
     
- 
 %7D%0A      
 //%0A 
@@ -701,19 +701,14 @@
     
-//
 %0A     
- //
     
@@ -778,27 +778,24 @@
 rlaced%0A     
- //
      result.
@@ -832,23 +832,20 @@
 ;%0A      
-//
     
- 
 fs.unlin
@@ -869,46 +869,25 @@
     
-//
     
- setTimeout(done, 110000
+done(
 );%0A     
  // 
@@ -882,19 +882,16 @@
 );%0A     
- //
    %7D);%0A 
@@ -894,19 +894,16 @@
 );%0A     
- //
  %7D);%0A   

Enable test code and fix issue causing tests to timeout on linux failure.