Add spec for crashing node process

This commit is contained in:
Kevin Sawicki 2017-01-24 13:49:45 -08:00
parent 241773f2f0
commit 170c51ae85
2 changed files with 84 additions and 43 deletions

View file

@ -1,4 +1,5 @@
const assert = require('assert') const assert = require('assert')
const childProcess = require('child_process')
const http = require('http') const http = require('http')
const multiparty = require('multiparty') const multiparty = require('multiparty')
const path = require('path') const path = require('path')
@ -40,51 +41,34 @@ describe('crashReporter module', function () {
this.timeout(120000) this.timeout(120000)
var called = false startServer({
var server = http.createServer(function (req, res) { callback (port) {
server.close() const crashUrl = url.format({
var form = new multiparty.Form() protocol: 'file',
form.parse(req, function (error, fields) { pathname: path.join(fixtures, 'api', 'crash.html'),
if (error) throw error search: '?port=' + port
if (called) return
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())
const reportId = 'abc-123-def-456-abc-789-abc-123-abcd'
res.end(reportId, () => {
waitForCrashReport().then(() => {
assert.equal(crashReporter.getLastCrashReport().id, reportId)
assert.notEqual(crashReporter.getUploadedReports().length, 0)
assert.equal(crashReporter.getUploadedReports()[0].id, reportId)
done()
}, done)
}) })
}) w.loadURL(crashUrl)
},
processType: 'renderer',
done: done
}) })
var port = remote.process.port })
server.listen(port, '127.0.0.1', function () {
port = server.address().port it('should send minidump when node processes crash', function (done) {
remote.process.port = port if (isCI) return done()
const crashUrl = url.format({
protocol: 'file', this.timeout(120000)
pathname: path.join(fixtures, 'api', 'crash.html'),
search: '?port=' + port startServer({
}) callback (port) {
if (process.platform === 'darwin') { const crashesDir = path.join(app.getPath('temp'), `${app.getName()} Crashes`)
crashReporter.start({ const version = app.getVersion()
companyName: 'Umbrella Corporation', const crashPath = path.join(fixtures, 'module', 'crash.js')
submitURL: 'http://127.0.0.1:' + port childProcess.fork(crashPath, [port, version, crashesDir], {silent: true})
}) },
} processType: 'browser',
w.loadURL(crashUrl) done: done
}) })
}) })
@ -155,3 +139,47 @@ const waitForCrashReport = () => {
checkForReport() checkForReport()
}) })
} }
const startServer = ({callback, processType, done}) => {
var called = false
var server = http.createServer((req, res) => {
server.close()
var form = new multiparty.Form()
form.parse(req, (error, fields) => {
if (error) throw error
if (called) return
called = true
assert.equal(fields.prod, 'Electron')
assert.equal(fields.ver, process.versions.electron)
assert.equal(fields.process_type, processType)
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())
const reportId = 'abc-123-def-456-abc-789-abc-123-abcd'
res.end(reportId, () => {
waitForCrashReport().then(() => {
assert.equal(crashReporter.getLastCrashReport().id, reportId)
assert.notEqual(crashReporter.getUploadedReports().length, 0)
assert.equal(crashReporter.getUploadedReports()[0].id, reportId)
done()
}, done)
})
})
})
let {port} = remote.process
server.listen(port, '127.0.0.1', () => {
port = server.address().port
remote.process.port = port
if (process.platform === 'darwin') {
crashReporter.start({
companyName: 'Umbrella Corporation',
submitURL: 'http://127.0.0.1:' + port
})
}
callback(port)
})
}

13
spec/fixtures/module/crash.js vendored Normal file
View file

@ -0,0 +1,13 @@
process.crashReporter.start({
productName: 'Zombies',
companyName: 'Umbrella Corporation',
crashesDirectory: process.argv[4],
submitURL: `http://127.0.0.1:${process.argv[2]}`,
extra: {
extra1: 'extra1',
extra2: 'extra2',
_version: process.argv[3]
}
})
process.nextTick(() => process.crash())