File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -36,8 +36,20 @@ function build(_styles) {
36
36
return applyStyle . apply ( builder , arguments ) ;
37
37
} ;
38
38
39
+ var self = this ;
40
+
39
41
builder . _styles = _styles ;
40
- builder . enabled = this . enabled ;
42
+
43
+ Object . defineProperty ( builder , 'enabled' , {
44
+ enumerable : true ,
45
+ get : function ( ) {
46
+ return self . enabled ;
47
+ } ,
48
+ set : function ( v ) {
49
+ self . enabled = v ;
50
+ }
51
+ } ) ;
52
+
41
53
// __proto__ is used because we must return a function, but there is
42
54
// no way to create a function with a different prototype.
43
55
/* eslint-disable no-proto */
Original file line number Diff line number Diff line change @@ -138,6 +138,28 @@ describe('chalk.enabled', function () {
138
138
assert . equal ( chalk . red ( 'foo' ) , 'foo' ) ;
139
139
chalk . enabled = true ;
140
140
} ) ;
141
+
142
+ it ( 'should enable/disable colors based on overall chalk enabled property, not individual instances' , function ( ) {
143
+ chalk . enabled = true ;
144
+ var red = chalk . red ;
145
+ assert . equal ( red . enabled , true ) ;
146
+ chalk . enabled = false ;
147
+ assert . equal ( red . enabled , chalk . enabled ) ;
148
+ chalk . enabled = true ;
149
+ } ) ;
150
+
151
+ it ( 'should propagate enable/disable changes from child colors' , function ( ) {
152
+ chalk . enabled = true ;
153
+ var red = chalk . red ;
154
+ assert . equal ( red . enabled , true ) ;
155
+ assert . equal ( chalk . enabled , true ) ;
156
+ red . enabled = false ;
157
+ assert . equal ( red . enabled , false ) ;
158
+ assert . equal ( chalk . enabled , false ) ;
159
+ chalk . enabled = true ;
160
+ assert . equal ( red . enabled , true ) ;
161
+ assert . equal ( chalk . enabled , true ) ;
162
+ } ) ;
141
163
} ) ;
142
164
143
165
describe ( 'chalk.constructor' , function ( ) {
You can’t perform that action at this time.
0 commit comments