Restart crash service in each spec
authorKevin Sawicki <kevin@github.com>
Wed, 19 Apr 2017 23:32:43 +0000 (16:32 -0700)
committerKevin Sawicki <kevinsawicki@gmail.com>
Wed, 19 Apr 2017 23:37:24 +0000 (16:37 -0700)
lib/common/api/crash-reporter.js
spec/api-crash-reporter-spec.js
spec/fixtures/api/crash-restart.html
spec/fixtures/api/crash.html
spec/static/main.js

index 658622e..7a54e24 100644 (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
       })
index e016b05..3ed81c4 100644 (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
+      }
+    }
+  }
+}
index 2f55c53..22f3b45 100644 (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')
index 6a1433a..8b64edd 100644 (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')
 }
index 1ac489e..033a0c5 100644 (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)