Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { errors, helpers, ONE_AND_DONES } = require('./mocha')
const run = require('mocha/lib/cli/run')
const ansi = require('ansi-colors')
const symbols = require('log-symbols')
const util = require('util')

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

ipc.on('console-call', print)

// Undocumented call in electron-window
win._loadURLWithArgs(
argv.url ? argv.url : join(__dirname, '../renderer/index.html'),
Expand Down Expand Up @@ -226,3 +229,8 @@ const fail = (error, trace) => {
const warn = warning => {
console.warn(ansi.yellow(`Warning: ${warning.message}`))
}

const print = (_, method, args) => {
const output = util.format.apply(null, args)
console[method](output)
}
17 changes: 10 additions & 7 deletions renderer/console.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const { remote } = require('electron')
const remoteConsole = remote.require('console')
const { ipcRenderer: ipc } = require('electron')

console.log = (...args) => {
remoteConsole.log(...args)
}
const { hasOwnProperty } = Object.prototype

console.dir = (...args) => {
remoteConsole.dir(...args)
const fakeConsole = {}
for (const k in console) {
if (hasOwnProperty.call(console, k) && k !== 'assert') {
fakeConsole[k] = (...args) => ipc.send('console-call', k, args)
}
}
global.__defineGetter__('console', function () {
return fakeConsole
})