From f5afa636756de67b6c34fbf02761e9d067eb26f5 Mon Sep 17 00:00:00 2001 From: artemave Date: Tue, 2 Jul 2019 16:34:14 +0200 Subject: [PATCH 1/2] Use `console.log` instead of `console.debug` In the browser, `console.debug` does not output anything by default. From MDN (https://developer.mozilla.org/en-US/docs/Web/API/Console): "Starting with Chromium 58 this method only appears in Chromium browser consoles when level "Verbose" is selected." --- src/browser.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/browser.js b/src/browser.js index ac3f7e13..a13a9d7c 100644 --- a/src/browser.js +++ b/src/browser.js @@ -169,14 +169,11 @@ function formatArgs(args) { } /** - * Invokes `console.debug()` when available. - * No-op when `console.debug` is not a "function". - * If `console.debug` is not available, falls back - * to `console.log`. + * Invokes `console.log` if available or no-op * * @api public */ -exports.log = console.debug || console.log || (() => {}); +exports.log = console.log || (() => {}); /** * Save `namespaces`. From e407309bfd4676b144168a18216bd8824a9d6aa1 Mon Sep 17 00:00:00 2001 From: artemave Date: Tue, 2 Jul 2019 16:37:12 +0200 Subject: [PATCH 2/2] Add flag to force Node colors So that process that runs in Electron renderer process can log to the terminal if it runs in a headless mode, but to the browser console if it runs with the browser window. Use case: run browser tests in electron-mocha renderer with or without browser window. --- README.md | 1 + src/index.js | 5 ++++- src/node.js | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 88dae35d..9fabfd50 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,7 @@ change the behavior of the debug logging: | `DEBUG` | Enables/disables specific debugging namespaces. | | `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). | | `DEBUG_COLORS`| Whether or not to use colors in the debug output. | +| `DEBUG_COLORS_NODE` | Assume runtime is Node, even if it looks like a browser (e.g. Electron). | | `DEBUG_DEPTH` | Object inspection depth. | | `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. | diff --git a/src/index.js b/src/index.js index bf4c57f2..cdc34d8a 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,10 @@ * treat as a browser. */ -if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) { +const isBrowserNode = process.type === 'renderer' || process.browser === true || process.__nwjs; +const isBrowser = typeof process === 'undefined'; + +if (isBrowser || (isBrowserNode && !process.env.DEBUG_COLORS_NODE)) { module.exports = require('./browser.js'); } else { module.exports = require('./node.js'); diff --git a/src/node.js b/src/node.js index 5e1f1541..c2fa8610 100644 --- a/src/node.js +++ b/src/node.js @@ -128,6 +128,11 @@ exports.inspectOpts = Object.keys(process.env).filter(key => { return k.toUpperCase(); }); + if (prop === 'colorsNode') { + obj.colors = true; + return obj; + } + // Coerce string value into JS value let val = process.env[key]; if (/^(yes|on|true|enabled)$/i.test(val)) {