Skip to content

Commit 6404365

Browse files
committed
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.
1 parent f5afa63 commit 6404365

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ change the behavior of the debug logging:
168168
| `DEBUG` | Enables/disables specific debugging namespaces. |
169169
| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). |
170170
| `DEBUG_COLORS`| Whether or not to use colors in the debug output. |
171+
| `DEBUG_COLORS_NODE` | Assume runtime is Node, even if it looks like a browser (e.g. Electron). |
171172
| `DEBUG_DEPTH` | Object inspection depth. |
172173
| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. |
173174

src/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
* treat as a browser.
44
*/
55

6-
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
6+
const isBrowserNode = process.type === 'renderer' || process.browser === true || process.__nwjs;
7+
const isBrowser = typeof process === 'undefined'
8+
9+
if (isBrowser || (isBrowserNode && !process.env.DEBUG_COLORS_NODE)) {
710
module.exports = require('./browser.js');
811
} else {
912
module.exports = require('./node.js');

src/node.js

+5
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ exports.inspectOpts = Object.keys(process.env).filter(key => {
128128
return k.toUpperCase();
129129
});
130130

131+
if (prop === 'colorsNode') {
132+
obj.colors = true;
133+
return obj;
134+
}
135+
131136
// Coerce string value into JS value
132137
let val = process.env[key];
133138
if (/^(yes|on|true|enabled)$/i.test(val)) {

0 commit comments

Comments
 (0)