var assert = require('assert')
var path = require('path')

var minidump = require('..')
var electronDownload = require('electron-download')
var extractZip = require('extract-zip')
var temp = require('temp').track()

describe('minidump', function () {
  this.timeout(60000)

  describe('walkStack()', function () {
    describe('macOS dump', function () {
      it('calls back with a report', function (done) {
        downloadElectronSymbols('darwin', function (error, symbolsPath) {
          if (error) return done(error)

          var dumpPath = path.join(__dirname, 'fixtures', 'mac.dmp')
          minidump.walkStack(dumpPath, symbolsPath, function (error, report) {
            if (error) return done(error)

            report = report.toString()
            assert.notEqual(report.length, 0)
            assert.notEqual(report.indexOf('Electron Framework!atom::(anonymous namespace)::Crash() [atom_bindings.cc : 27 + 0x0]'), -1)
            done()
          })
        })
      })
    })

    describe('Windows dump', function () {
      it('calls back with a report', function (done) {
        downloadElectronSymbols('win32', function (error, symbolsPath) {
          if (error) return done(error)

          var dumpPath = path.join(__dirname, 'fixtures', 'windows.dmp')
          minidump.walkStack(dumpPath, symbolsPath, function (error, report) {
            if (error) return done(error)

            report = report.toString()
            assert.notEqual(report.length, 0)
            assert.notEqual(report.indexOf('electron.exe!atom::`anonymous namespace\'::Crash [atom_bindings.cc : 27 + 0x0]'), -1)
            done()
          })
        })
      })
    })
  })
})

var downloadElectronSymbols = function (platform, callback) {
  electronDownload({
    version: '1.4.3', // Dumps were generated with Electron 1.4.3 x64
    arch: 'x64',
    platform: platform,
    symbols: true,
    quiet: true
  }, function (error, zipPath) {
    if (error) return callback(error)

    var symbolsPath = temp.mkdirSync('node-minidump-')
    extractZip(zipPath, {dir: symbolsPath}, function (error) {
      if (error) return callback(error)
      callback(null, path.join(symbolsPath, 'electron.breakpad.syms'))
   })
  })
}

@@ -725,33 +725,50 @@
     
-report = report.toString(
+assert.equal(Buffer.isBuffer(report), true
 )%0A  
@@ -802,32 +802,72 @@
 eport.length, 0)
+%0A%0A            report = report.toString()
 %0A            ass
@@ -1471,33 +1471,50 @@
     
-report = report.toString(
+assert.equal(Buffer.isBuffer(report), true
 )%0A  
@@ -1556,16 +1556,56 @@
 ngth, 0)
+%0A%0A            report = report.toString()
 %0A       
@@ -1791,18 +1791,1015 @@
 %7D)%0A  %7D)%0A
+%0A  describe('dumpSymbol()', function () %7B%0A    it('calls back with a minidump', function (done) %7B%0A      if (process.platform !== 'darwin') return this.skip()%0A%0A      downloadElectron(function (error, binaryPath) %7B%0A        if (error) return done(error)%0A        minidump.dumpSymbol(binaryPath, function (error, minidump) %7B%0A          if (error) return done(error)%0A%0A          assert.equal(Buffer.isBuffer(minidump), true)%0A          assert.notEqual(minidump.length, 0)%0A          done()%0A        %7D)%0A      %7D)%0A    %7D)%0A  %7D)%0A%7D)%0A%0Avar downloadElectron = function (callback) %7B%0A  electronDownload(%7B%0A    version: '1.4.3',%0A    arch: 'x64',%0A    platform: 'darwin',%0A    quiet: true%0A  %7D, function (error, zipPath) %7B%0A    if (error) return callback(error)%0A%0A    var electronPath = temp.mkdirSync('node-minidump-')%0A    extractZip(zipPath, %7Bdir: electronPath%7D, function (error) %7B%0A      if (error) return callback(error)%0A      callback(null, path.join(electronPath, 'Electron.app', 'Contents', 'MacOS', 'Electron'))%0A   %7D)%0A  %7D)%0A
 %7D
-)
 %0A%0Avar do

Add initial dumpSymbol test