|
| 1 | +const { ipcRenderer: ipc } = require('electron') |
1 | 2 | const { files, ...opts } = window.__args__
|
2 | 3 |
|
3 | 4 | if (!opts.interactive) {
|
4 | 5 | require('./console')
|
5 | 6 | }
|
6 | 7 |
|
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 |
| - |
24 | 8 | const fail = error => {
|
25 | 9 | ipc.send('mocha-error', {
|
26 | 10 | message: error.message || error,
|
27 | 11 | stack: error.stack
|
28 | 12 | })
|
29 | 13 | }
|
30 | 14 |
|
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 | + } |
34 | 31 |
|
35 |
| -window.addEventListener('error', fail) |
36 |
| -window.addEventListener('unhandledrejection', e => fail(e.reason)) |
| 32 | + // Expose Mocha for browser tests |
| 33 | + window.mocha = Mocha |
37 | 34 |
|
38 |
| -handleScripts(opts.script) |
| 35 | + handleScripts(opts.script) |
39 | 36 |
|
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 | + }) |
49 | 46 |
|
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