|
| 1 | +var assert = require('assert') |
| 2 | +var path = require('path') |
| 3 | + |
| 4 | +var minidump = require('..') |
| 5 | +var electronDownload = require('electron-download') |
| 6 | +var extractZip = require('extract-zip') |
| 7 | +var temp = require('temp').track() |
| 8 | + |
| 9 | +describe('minidump', function () { |
| 10 | + this.timeout(60000) |
| 11 | + |
| 12 | + describe('walkStack()', function () { |
| 13 | + describe('macOS dump', function () { |
| 14 | + it('calls back with a report', function (done) { |
| 15 | + downloadElectronSymbols('darwin', function (error, symbolsPath) { |
| 16 | + if (error) return done(error) |
| 17 | + |
| 18 | + var dumpPath = path.join(__dirname, 'fixtures', 'mac.dmp') |
| 19 | + minidump.walkStack(dumpPath, symbolsPath, function (error, report) { |
| 20 | + if (error) return done(error) |
| 21 | + |
| 22 | + assert.equal(Buffer.isBuffer(report), true) |
| 23 | + assert.notEqual(report.length, 0) |
| 24 | + |
| 25 | + report = report.toString() |
| 26 | + assert.notEqual(report.indexOf('Electron Framework!atom::(anonymous namespace)::Crash() [atom_bindings.cc : 27 + 0x0]'), -1) |
| 27 | + done() |
| 28 | + }) |
| 29 | + }) |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + describe('Windows dump', function () { |
| 34 | + it('calls back with a report', function (done) { |
| 35 | + downloadElectronSymbols('win32', function (error, symbolsPath) { |
| 36 | + if (error) return done(error) |
| 37 | + |
| 38 | + var dumpPath = path.join(__dirname, 'fixtures', 'windows.dmp') |
| 39 | + minidump.walkStack(dumpPath, symbolsPath, function (error, report) { |
| 40 | + if (error) return done(error) |
| 41 | + |
| 42 | + assert.equal(Buffer.isBuffer(report), true) |
| 43 | + assert.notEqual(report.length, 0) |
| 44 | + |
| 45 | + report = report.toString() |
| 46 | + assert.notEqual(report.indexOf('electron.exe!atom::`anonymous namespace\'::Crash [atom_bindings.cc : 27 + 0x0]'), -1) |
| 47 | + done() |
| 48 | + }) |
| 49 | + }) |
| 50 | + }) |
| 51 | + }) |
| 52 | + }) |
| 53 | + |
| 54 | + describe('dumpSymbol()', function () { |
| 55 | + it('calls back with a minidump', function (done) { |
| 56 | + if (process.platform !== 'darwin') return this.skip() |
| 57 | + |
| 58 | + downloadElectron(function (error, binaryPath) { |
| 59 | + if (error) return done(error) |
| 60 | + minidump.dumpSymbol(binaryPath, function (error, minidump) { |
| 61 | + if (error) return done(error) |
| 62 | + |
| 63 | + assert.equal(Buffer.isBuffer(minidump), true) |
| 64 | + assert.notEqual(minidump.length, 0) |
| 65 | + done() |
| 66 | + }) |
| 67 | + }) |
| 68 | + }) |
| 69 | + }) |
| 70 | +}) |
| 71 | + |
| 72 | +var downloadElectron = function (callback) { |
| 73 | + electronDownload({ |
| 74 | + version: '1.4.3', |
| 75 | + arch: 'x64', |
| 76 | + platform: 'darwin', |
| 77 | + quiet: true |
| 78 | + }, function (error, zipPath) { |
| 79 | + if (error) return callback(error) |
| 80 | + |
| 81 | + var electronPath = temp.mkdirSync('node-minidump-') |
| 82 | + extractZip(zipPath, {dir: electronPath}, function (error) { |
| 83 | + if (error) return callback(error) |
| 84 | + callback(null, path.join(electronPath, 'Electron.app', 'Contents', 'MacOS', 'Electron')) |
| 85 | + }) |
| 86 | + }) |
| 87 | +} |
| 88 | + |
| 89 | +var downloadElectronSymbols = function (platform, callback) { |
| 90 | + electronDownload({ |
| 91 | + version: '1.4.3', // Dumps were generated with Electron 1.4.3 x64 |
| 92 | + arch: 'x64', |
| 93 | + platform: platform, |
| 94 | + symbols: true, |
| 95 | + quiet: true |
| 96 | + }, function (error, zipPath) { |
| 97 | + if (error) return callback(error) |
| 98 | + |
| 99 | + var symbolsPath = temp.mkdirSync('node-minidump-') |
| 100 | + extractZip(zipPath, {dir: symbolsPath}, function (error) { |
| 101 | + if (error) return callback(error) |
| 102 | + callback(null, path.join(symbolsPath, 'electron.breakpad.syms')) |
| 103 | + }) |
| 104 | + }) |
| 105 | +} |
0 commit comments