diff --git a/lib/common/api/crash-reporter.js b/lib/common/api/crash-reporter.js index 658622e8f5a7..7a54e24fbc2a 100644 --- a/lib/common/api/crash-reporter.js +++ b/lib/common/api/crash-reporter.js @@ -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 }) diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index e016b05f1d48..3ed81c40b147 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -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 + } + } + } +} diff --git a/spec/fixtures/api/crash-restart.html b/spec/fixtures/api/crash-restart.html index 2f55c539bbd8..22f3b45b5c82 100644 --- a/spec/fixtures/api/crash-restart.html +++ b/spec/fixtures/api/crash-restart.html @@ -3,7 +3,7 @@