@@ -4,10 +4,27 @@ import {getUserCodeFrame} from './get-user-code-frame'
44import { getDocument } from './helpers'
55import { getConfig } from './config'
66
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+ }
1128
1229const { DOMCollection} = prettyFormat . plugins
1330
@@ -61,7 +78,7 @@ function prettyDOM(dom, maxLength, options = {}) {
6178 const debugContent = prettyFormat . format ( dom , {
6279 plugins : [ createDOMElementFilter ( filterNode ) , DOMCollection ] ,
6380 printFunctionName : false ,
64- highlight : inNode ( ) ,
81+ highlight : shouldHighlight ( ) ,
6582 ...prettyFormatOptions ,
6683 } )
6784 return maxLength !== undefined && dom . outerHTML . length > maxLength
0 commit comments