Skip to content

Commit 34d9224

Browse files
committed
Let mocha handle uncaught errors outside of tests
See jprichardson#143
1 parent 61c692f commit 34d9224

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

renderer/run.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1+
const { ipcRenderer: ipc } = require('electron')
12
const { files, ...opts } = window.__args__
23

34
if (!opts.interactive) {
45
require('./console')
56
}
67

7-
const { Mocha, helpers } = require('../lib/mocha')
8-
const { ipcRenderer: ipc } = require('electron')
9-
10-
const handleScripts = (scripts = []) => {
11-
for (let script of scripts) {
12-
let tag = document.createElement('script')
13-
tag.src = script
14-
tag.async = false
15-
tag.onerror = () => {
16-
ipc.send('mocha-warn', {
17-
message: `script not found: ${script}`
18-
})
19-
}
20-
document.head.appendChild(tag)
21-
}
22-
}
23-
248
const fail = error => {
259
ipc.send('mocha-error', {
2610
message: error.message || error,
2711
stack: error.stack
2812
})
2913
}
3014

31-
process.on('SIGINT', () => console.log('sigint'))
32-
// Expose Mocha for browser tests
33-
window.mocha = Mocha
15+
try {
16+
const { Mocha, helpers } = require('../lib/mocha')
17+
18+
const handleScripts = (scripts = []) => {
19+
for (let script of scripts) {
20+
let tag = document.createElement('script')
21+
tag.src = script
22+
tag.async = false
23+
tag.onerror = () => {
24+
ipc.send('mocha-warn', {
25+
message: `script not found: ${script}`
26+
})
27+
}
28+
document.head.appendChild(tag)
29+
}
30+
}
3431

35-
window.addEventListener('error', fail)
36-
window.addEventListener('unhandledrejection', e => fail(e.reason))
32+
// Expose Mocha for browser tests
33+
window.mocha = Mocha
3734

38-
handleScripts(opts.script)
35+
handleScripts(opts.script)
3936

40-
ipc.on('mocha-start', () => {
41-
try {
42-
helpers.runMocha(opts, files, (...args) => {
43-
ipc.send('mocha-done', ...args)
44-
})
45-
} catch (error) {
46-
fail(error)
47-
}
48-
})
37+
ipc.on('mocha-start', () => {
38+
try {
39+
helpers.runMocha(opts, files, (...args) => {
40+
ipc.send('mocha-done', ...args)
41+
})
42+
} catch (e) {
43+
fail(e)
44+
}
45+
})
4946

50-
// Request re-run on reload in --interactive mode
51-
ipc.send('mocha-ready-to-run')
47+
// Request re-run on reload in --interactive mode
48+
ipc.send('mocha-ready-to-run')
49+
} catch (e) {
50+
fail(e)
51+
}

0 commit comments

Comments
 (0)