From 29decbdd4dfbe6305a2b3d78e4d241dfa75c89ad Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Thu, 13 Jun 2019 15:56:58 -0700 Subject: [PATCH] ci: make console.warn work in tests (#18771) --- spec/chromium-spec.js | 20 ++++++++++++++++++-- spec/static/index.html | 11 +++++++---- spec/static/main.js | 7 +++---- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 48af78f6cf6f..fb2db5f8f90e 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -32,6 +32,11 @@ describe('chromium feature', () => { listener = null }) + afterEach(async () => { + await closeWindow(w) + w = null + }) + describe('command line switches', () => { describe('--lang switch', () => { const currentLocale = app.getLocale() @@ -78,8 +83,6 @@ describe('chromium feature', () => { }) }) - afterEach(() => closeWindow(w).then(() => { w = null })) - describe('heap snapshot', () => { it('does not crash', function () { process.electronBinding('v8_util').takeHeapSnapshot() @@ -1466,6 +1469,19 @@ describe('chromium feature', () => { }) }) +describe('console functions', () => { + it('should exist', () => { + expect(console.log, 'log').to.be.a('function') + expect(console.error, 'error').to.be.a('function') + expect(console.warn, 'warn').to.be.a('function') + expect(console.info, 'info').to.be.a('function') + expect(console.debug, 'debug').to.be.a('function') + expect(console.trace, 'trace').to.be.a('function') + expect(console.time, 'time').to.be.a('function') + expect(console.timeEnd, 'timeEnd').to.be.a('function') + }) +}) + describe('font fallback', () => { async function getRenderedFonts (html) { const w = new BrowserWindow({ show: false }) diff --git a/spec/static/index.html b/spec/static/index.html index 6f82f7267bee..db2dacfb3632 100644 --- a/spec/static/index.html +++ b/spec/static/index.html @@ -39,11 +39,14 @@ // Rediret all output to browser. if (isCi) { - global.__defineGetter__('console', function () { - return { - log: (...args) => ipcRenderer.send('console.log', args), - error: (...args) => ipcRenderer.send('console.error', args) + const fakeConsole = {} + for (const k in console) { + if (console.hasOwnProperty(k) && k !== 'assert') { + fakeConsole[k] = (...args) => ipcRenderer.send('console-call', k, args) } + } + global.__defineGetter__('console', function () { + return fakeConsole }) } diff --git a/spec/static/main.js b/spec/static/main.js index d1ddd3637bec..34d61e42de90 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -52,16 +52,15 @@ if (process.platform !== 'darwin') { // Write output to file if OUTPUT_TO_FILE is defined. const outputToFile = process.env.OUTPUT_TO_FILE -const print = function (_, args) { +const print = function (_, method, args) { const output = util.format.apply(null, args) if (outputToFile) { fs.appendFileSync(outputToFile, output + '\n') } else { - console.error(output) + console[method](output) } } -ipcMain.on('console.log', print) -ipcMain.on('console.error', print) +ipcMain.on('console-call', print) ipcMain.on('process.exit', function (event, code) { process.exit(code)