Skip to content

Commit 0760df9

Browse files
alexeykuzmininukshuk
authored andcommitted
refactor: do not use "remote" module for console calls
1 parent aace6b6 commit 0760df9

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/run.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { errors, helpers, ONE_AND_DONES } = require('./mocha')
77
const run = require('mocha/lib/cli/run')
88
const ansi = require('ansi-colors')
99
const symbols = require('log-symbols')
10+
const util = require('util')
1011

1112
exports.command = run.command
1213
exports.describe = 'Run tests with Electron-Mocha'
@@ -188,6 +189,8 @@ exports.handler = async argv => {
188189
})
189190
ipc.on('mocha-warn', (_, warning) => warn(warning))
190191

192+
ipc.on('console-call', print)
193+
191194
// Undocumented call in electron-window
192195
win._loadURLWithArgs(
193196
argv.url ? argv.url : join(__dirname, '../renderer/index.html'),
@@ -226,3 +229,8 @@ const fail = (error, trace) => {
226229
const warn = warning => {
227230
console.warn(ansi.yellow(`Warning: ${warning.message}`))
228231
}
232+
233+
const print = (_, method, args) => {
234+
const output = util.format.apply(null, args)
235+
console[method](output)
236+
}

renderer/console.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
const { remote } = require('electron')
2-
const remoteConsole = remote.require('console')
1+
const { ipcRenderer: ipc } = require('electron')
32

4-
console.log = (...args) => {
5-
remoteConsole.log(...args)
6-
}
3+
const { hasOwnProperty } = Object.prototype
74

8-
console.dir = (...args) => {
9-
remoteConsole.dir(...args)
5+
const fakeConsole = {}
6+
for (const k in console) {
7+
if (hasOwnProperty.call(console, k) && k !== 'assert') {
8+
fakeConsole[k] = (...args) => ipc.send('console-call', k, args)
9+
}
1010
}
11+
global.__defineGetter__('console', function () {
12+
return fakeConsole
13+
})

0 commit comments

Comments
 (0)