function logTestModule(module){
  console.log('\n==========\n' + module + '\n==========\n')
}
function logTestProto(proto){
  console.log('==> ' + proto)
}

var MAGNET = "magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4"
var OK = {
  'log': false,
  'client': false
}

/*
* TEST LOG
*/
function testLog(cb){
  logTestModule('Log')
  var Log = require('./log.js')

  logTestProto('print')
  Log.print('Print ok')

  logTestProto('echo')
  Log.echo('Echo ok')

  setTimeout(function(){
    delete Log
    cb(true)
  }, 1000)
}

testLog(function(value){
  OK.log = value
})

/*
* TEST CLIENT
*/
function testClient(cb){
  logTestModule('Client')
  var Client = require('./client.js')
  var c = new Client()

  logTestProto('on start')
  c.on('start', function(hash){
    console.log('Client start trigger')
    console.log('Hash: ' + hash)

    logTestProto('getTorrent')
    var torrent = c.getTorrent()
    console.log('Torrent: ')
    console.log(torrent)
  })

  logTestProto('on download')
  c.on('download', function(torrent){
    console.log('Client download trigger')
    console.log('Torrent: ')
    console.log(torrent)

    logTestProto('stop')
    c.stop()
  })

  logTestProto('on done')
  c.on('done', function(hash, name){
    console.log('Client done trigger')
    console.log('Hash: ' + hash + '\nName: ' + name)

    cb(true)
    delete Client
    delete c
  })

  c.download(MAGNET)
}

testClient(function(value){
  OK.client = value
})

var end = true
do {
  end = true
  for (var key in OK){
    end = end && OK[key]
  }
} while (!end)

process.exit(0)

@@ -1692,16 +1692,41 @@
 lue%0A%7D)%0A%0A
+setTimeout(function()%7B%0A  
 var end 
@@ -1736,13 +1736,17 @@
 rue%0A
+  
 do %7B%0A
+  
   en
@@ -1756,16 +1756,18 @@
  true%0A  
+ 
+ 
 for (var
@@ -1779,16 +1779,18 @@
 in OK)%7B%0A
+  
     end 
@@ -1808,18 +1808,22 @@
 %5Bkey%5D%0A  
-%7D%0A
+  %7D%0A  
 %7D while 
@@ -1830,16 +1830,18 @@
 (!end)%0A%0A
+  
 process.
@@ -1848,8 +1848,17 @@
 exit(0)%0A
+%7D, 1000)%0A

fix test