electron/spec/api-crash-reporter-spec.js

93 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-03-25 20:03:49 +00:00
const assert = require('assert')
const http = require('http')
const multiparty = require('multiparty')
const path = require('path')
const url = require('url')
2016-01-12 02:40:23 +00:00
2016-03-25 20:03:49 +00:00
const remote = require('electron').remote
const app = remote.require('electron').app
const crashReporter = remote.require('electron').crashReporter
const BrowserWindow = remote.require('electron').BrowserWindow
2016-01-12 02:40:23 +00:00
2016-03-25 20:03:49 +00:00
describe('crash-reporter module', function () {
var fixtures = path.resolve(__dirname, 'fixtures')
var w = null
2016-03-25 20:03:49 +00:00
beforeEach(function () {
2016-02-17 01:39:11 +00:00
w = new BrowserWindow({
2016-01-12 02:40:23 +00:00
show: false
2016-03-25 20:03:49 +00:00
})
})
2016-03-25 20:03:49 +00:00
afterEach(function () {
w.destroy()
})
2016-01-12 02:40:23 +00:00
if (process.mas) {
2016-03-25 20:03:49 +00:00
return
2016-01-12 02:40:23 +00:00
}
2016-03-25 20:03:49 +00:00
var isCI = remote.getGlobal('isCi')
2016-01-12 02:40:23 +00:00
if (isCI) {
2016-03-25 20:03:49 +00:00
return
2016-01-12 02:40:23 +00:00
}
2016-03-25 20:03:49 +00:00
it('should send minidump when renderer crashes', function (done) {
this.timeout(120000)
2016-03-25 20:03:49 +00:00
var called = false
var server = http.createServer(function (req, res) {
server.close()
var form = new multiparty.Form()
form.parse(req, function (error, fields) {
2016-03-28 23:33:16 +00:00
if (error) throw error
if (called) return
2016-03-25 20:03:49 +00:00
called = true
assert.equal(fields['prod'], 'Electron')
assert.equal(fields['ver'], process.versions['electron'])
assert.equal(fields['process_type'], 'renderer')
assert.equal(fields['platform'], process.platform)
assert.equal(fields['extra1'], 'extra1')
assert.equal(fields['extra2'], 'extra2')
assert.equal(fields['_productName'], 'Zombies')
assert.equal(fields['_companyName'], 'Umbrella Corporation')
assert.equal(fields['_version'], app.getVersion())
res.end('abc-123-def')
done()
})
})
var port = remote.process.port
server.listen(port, '127.0.0.1', function () {
port = server.address().port
remote.process.port = port
2016-02-17 00:46:49 +00:00
const crashUrl = url.format({
2016-01-12 02:40:23 +00:00
protocol: 'file',
pathname: path.join(fixtures, 'api', 'crash.html'),
2016-03-25 20:03:49 +00:00
search: '?port=' + port
})
2016-01-12 02:40:23 +00:00
if (process.platform === 'darwin') {
crashReporter.start({
companyName: 'Umbrella Corporation',
2016-03-25 20:03:49 +00:00
submitURL: 'http://127.0.0.1:' + port
})
2016-01-12 02:40:23 +00:00
}
2016-03-25 20:03:49 +00:00
w.loadURL(crashUrl)
})
})
2016-03-25 20:03:49 +00:00
describe('.start(options)', function () {
it('requires that the companyName and submitURL options be specified', function () {
assert.throws(function () {
2016-02-17 01:39:11 +00:00
crashReporter.start({
2016-01-12 02:40:23 +00:00
companyName: 'Missing submitURL'
2016-03-25 20:03:49 +00:00
})
})
assert.throws(function () {
2016-02-17 01:39:11 +00:00
crashReporter.start({
2016-01-12 02:40:23 +00:00
submitURL: 'Missing companyName'
2016-03-25 20:03:49 +00:00
})
})
})
})
})