Add failing spec for uncaught main process errors
This commit is contained in:
parent
a4e25a8917
commit
24fb560a9d
2 changed files with 33 additions and 12 deletions
|
@ -3,7 +3,7 @@ const ChildProcess = require('child_process')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const {remote} = require('electron')
|
const {ipcRenderer, remote} = require('electron')
|
||||||
|
|
||||||
const isCI = remote.getGlobal('isCi')
|
const isCI = remote.getGlobal('isCi')
|
||||||
|
|
||||||
|
@ -130,26 +130,32 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('throw error in node context', function () {
|
describe('error thrown in renderer process node context', function () {
|
||||||
it('gets caught', function (done) {
|
it('gets emitted as an process uncaughtException event', function (done) {
|
||||||
var error = new Error('boo!')
|
const error = new Error('boo!')
|
||||||
var lsts = process.listeners('uncaughtException')
|
const listeners = process.listeners('uncaughtException')
|
||||||
process.removeAllListeners('uncaughtException')
|
process.removeAllListeners('uncaughtException')
|
||||||
process.on('uncaughtException', function () {
|
process.on('uncaughtException', (thrown) => {
|
||||||
var i, len, lst
|
assert.strictEqual(thrown, error)
|
||||||
process.removeAllListeners('uncaughtException')
|
process.removeAllListeners('uncaughtException')
|
||||||
for (i = 0, len = lsts.length; i < len; i++) {
|
listeners.forEach((listener) => {
|
||||||
lst = lsts[i]
|
process.on('uncaughtException', listener)
|
||||||
process.on('uncaughtException', lst)
|
})
|
||||||
}
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
fs.readFile(__filename, function () {
|
fs.readFile(__filename, () => {
|
||||||
throw error
|
throw error
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('error thrown in main process node context', function () {
|
||||||
|
it('gets emitted as an process uncaughtException event', function () {
|
||||||
|
const error = ipcRenderer.sendSync('handle-uncaught-exception', 'hello')
|
||||||
|
assert.equal(error, 'hello')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('setTimeout called under Chromium event loop in browser process', function () {
|
describe('setTimeout called under Chromium event loop in browser process', function () {
|
||||||
it('can be scheduled in time', function (done) {
|
it('can be scheduled in time', function (done) {
|
||||||
remote.getGlobal('setTimeout')(done, 0)
|
remote.getGlobal('setTimeout')(done, 0)
|
||||||
|
|
|
@ -273,3 +273,18 @@ ipcMain.on('try-emit-web-contents-event', (event, id, eventName) => {
|
||||||
listenerCountAfter
|
listenerCountAfter
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('handle-uncaught-exception', (event, message) => {
|
||||||
|
const listeners = process.listeners('uncaughtException')
|
||||||
|
process.removeAllListeners('uncaughtException')
|
||||||
|
process.on('uncaughtException', (error) => {
|
||||||
|
process.removeAllListeners('uncaughtException')
|
||||||
|
listeners.forEach((listener) => {
|
||||||
|
process.on('uncaughtException', listener)
|
||||||
|
})
|
||||||
|
event.returnValue = error.message
|
||||||
|
})
|
||||||
|
fs.readFile(__filename, () => {
|
||||||
|
throw new Error(message)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue