@@ -4,10 +4,27 @@ import {getUserCodeFrame} from './get-user-code-frame'
4
4
import { getDocument } from './helpers'
5
5
import { getConfig } from './config'
6
6
7
- const inNode = ( ) =>
8
- typeof process !== 'undefined' &&
9
- process . versions !== undefined &&
10
- process . versions . node !== undefined
7
+ const shouldHighlight = ( ) => {
8
+ let colors
9
+ try {
10
+ colors = JSON . parse ( process ?. env ?. COLORS )
11
+ } catch ( e ) {
12
+ // If this throws, process?.env?.COLORS wasn't parsable. Since we only
13
+ // care about `true` or `false`, we can safely ignore the error.
14
+ }
15
+
16
+ if ( typeof colors === 'boolean' ) {
17
+ // If `colors` is set explicitly (both `true` and `false`), use that value.
18
+ return colors
19
+ } else {
20
+ // If `colors` is not set, colorize if we're in node.
21
+ return (
22
+ typeof process !== 'undefined' &&
23
+ process . versions !== undefined &&
24
+ process . versions . node !== undefined
25
+ )
26
+ }
27
+ }
11
28
12
29
const { DOMCollection} = prettyFormat . plugins
13
30
@@ -61,7 +78,7 @@ function prettyDOM(dom, maxLength, options = {}) {
61
78
const debugContent = prettyFormat . format ( dom , {
62
79
plugins : [ createDOMElementFilter ( filterNode ) , DOMCollection ] ,
63
80
printFunctionName : false ,
64
- highlight : inNode ( ) ,
81
+ highlight : shouldHighlight ( ) ,
65
82
...prettyFormatOptions ,
66
83
} )
67
84
return maxLength !== undefined && dom . outerHTML . length > maxLength
0 commit comments