Restart crash service in each spec

This commit is contained in:
Kevin Sawicki 2017-04-19 16:32:43 -07:00 committed by Kevin Sawicki
parent a7a92e1cd3
commit de62f1ea6c
5 changed files with 55 additions and 5 deletions

View file

@ -56,7 +56,7 @@ class CrashReporter {
const env = {
ELECTRON_INTERNAL_CRASH_SERVICE: 1
}
spawn(process.execPath, args, {
this._crashServiceProcess = spawn(process.execPath, args, {
env: env,
detached: true
})

View file

@ -46,6 +46,10 @@ describe('crashReporter module', function () {
return closeWindow(w).then(function () { w = null })
})
afterEach(function () {
stopCrashService()
})
afterEach(function (done) {
if (stopServer != null) {
stopServer(done)
@ -82,9 +86,24 @@ describe('crashReporter module', function () {
stopServer = startServer({
callback (port) {
const crashesDir = path.join(app.getPath('temp'), `${app.getName()} Crashes`)
const crashesDir = path.join(app.getPath('temp'), `Zombies Crashes`)
const version = app.getVersion()
const crashPath = path.join(fixtures, 'module', 'crash.js')
if (process.platform === 'win32') {
const crashServiceProcess = childProcess.spawn(process.execPath, [
`--reporter-url=http://127.0.0.1:${port}`,
'--application-name=Zombies',
`--crashes-directory=${crashesDir}`
], {
env: {
ELECTRON_INTERNAL_CRASH_SERVICE: 1
},
detached: true
})
remote.process.crashServicePid = crashServiceProcess.pid
}
childProcess.fork(crashPath, [port, version, crashesDir], {silent: true})
},
processType: 'browser',
@ -105,7 +124,7 @@ describe('crashReporter module', function () {
}
const testDone = (uploaded) => {
if (uploaded) {
return done(new Error('fail'))
return done(new Error('Uploaded crash report'))
}
if (process.platform === 'darwin') {
crashReporter.setUploadToServer(true)
@ -321,3 +340,17 @@ const startServer = ({callback, processType, done}) => {
})
}
}
const stopCrashService = () => {
const {crashServicePid} = remote.process
if (crashServicePid) {
remote.process.crashServicePid = 0
try {
process.kill(crashServicePid)
} catch (error) {
if (error.code !== 'ESRCH') {
throw error
}
}
}
}

View file

@ -3,7 +3,7 @@
<script type="text/javascript" charset="utf-8">
const {port} = require('url').parse(window.location.href, true).query
const {crashReporter} = require('electron')
const {crashReporter, ipcRenderer} = require('electron')
crashReporter.start({
productName: 'Zombies',
@ -18,6 +18,10 @@ crashReporter.start({
}
})
if (process.platform === 'win32') {
ipcRenderer.sendSync('crash-service-pid', crashReporter._crashServiceProcess.pid)
}
setImmediate(() => {
if (process.platform === 'darwin') {
crashReporter.setExtraParameter('extra2', 'extra2')

View file

@ -16,6 +16,11 @@ crashReporter.start({
'extra2': 'extra2',
}
});
if (process.platform === 'win32') {
ipcRenderer.sendSync('crash-service-pid', crashReporter._crashServiceProcess.pid)
}
if (!uploadToServer) {
ipcRenderer.sendSync('list-existing-dumps')
}

View file

@ -24,7 +24,10 @@ var argv = require('yargs')
.argv
var window = null
process.port = 0 // will be used by crash-reporter spec.
// will be used by crash-reporter spec.
process.port = 0
process.crashServicePid = 0
v8.setFlagsFromString('--expose_gc')
app.commandLine.appendSwitch('js-flags', '--expose_gc')
@ -329,6 +332,11 @@ ipcMain.on('navigate-with-pending-entry', (event, id) => {
})
})
ipcMain.on('crash-service-pid', (event, pid) => {
process.crashServicePid = pid
event.returnValue = null
})
// Suspend listeners until the next event and then restore them
const suspendListeners = (emitter, eventName, callback) => {
const listeners = emitter.listeners(eventName)