@@ -32,78 +32,71 @@ describe('build-exec-environment', () => {
3232
3333 describe ( 'inherited vars' , ( ) => {
3434 it ( 'should forward TERM when set' , ( ) => {
35- process . env . TERM = 'xterm-256color' ;
36- const ctx = { stdout : { isTTY : true } , stderr : { isTTY : true } , noColor : false } ;
35+ const ctx = { stdout : { isTTY : true } , env : { TERM : 'xterm-256color' } } ;
3736 const env = buildEnvironment ( ctx ) ;
3837 expect ( env . TERM ) . to . equal ( 'xterm-256color' ) ;
3938 } ) ;
4039
4140 it ( 'should not include TERM when unset' , ( ) => {
42- const ctx = { stdout : { isTTY : true } , stderr : { isTTY : true } , noColor : false } ;
41+ const ctx = { stdout : { isTTY : true } , env : { } } ;
4342 const env = buildEnvironment ( ctx ) ;
4443 expect ( env ) . to . not . have . property ( 'TERM' ) ;
4544 } ) ;
4645
4746 it ( 'should forward CI when set' , ( ) => {
48- process . env . CI = 'true' ;
49- const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , stderr : { isTTY : false } , noColor : false } ;
47+ const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , env : { CI : 'true' } } ;
5048 const env = buildEnvironment ( ctx ) ;
5149 expect ( env . CI ) . to . equal ( 'true' ) ;
5250 } ) ;
5351
5452 it ( 'should forward DEBUG when set' , ( ) => {
55- process . env . DEBUG = '*' ;
56- const ctx = { stdout : { isTTY : true } , stderr : { isTTY : true } , noColor : false } ;
53+ const ctx = { stdout : { isTTY : true } , env : { DEBUG : '*' } } ;
5754 const env = buildEnvironment ( ctx ) ;
5855 expect ( env . DEBUG ) . to . equal ( '*' ) ;
5956 } ) ;
6057
6158 it ( 'should forward TZ when set' , ( ) => {
62- process . env . TZ = 'America/New_York' ;
63- const ctx = { stdout : { isTTY : true } , stderr : { isTTY : true } , noColor : false } ;
59+ const ctx = { stdout : { isTTY : true } , env : { TZ : 'America/New_York' } } ;
6460 const env = buildEnvironment ( ctx ) ;
6561 expect ( env . TZ ) . to . equal ( 'America/New_York' ) ;
6662 } ) ;
6763
6864 it ( 'should not forward FORCE_COLOR when stdout is not a TTY' , ( ) => {
69- process . env . FORCE_COLOR = '1' ;
70- const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , stderr : { isTTY : false } , noColor : false } ;
65+ const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , env : { FORCE_COLOR : '1' } } ;
7166 const env = buildEnvironment ( ctx ) ;
7267 expect ( env ) . to . not . have . property ( 'FORCE_COLOR' ) ;
7368 } ) ;
7469
7570 it ( 'should not forward CLICOLOR_FORCE when stdout is not a TTY' , ( ) => {
76- process . env . CLICOLOR_FORCE = '3' ;
77- const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , stderr : { isTTY : false } , noColor : false } ;
71+ const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , env : { CLICOLOR_FORCE : '3' } } ;
7872 const env = buildEnvironment ( ctx ) ;
7973 expect ( env ) . to . not . have . property ( 'CLICOLOR_FORCE' ) ;
8074 } ) ;
8175
8276 it ( 'should still forward NO_COLOR when stdout is not a TTY' , ( ) => {
83- process . env . NO_COLOR = '1' ;
84- const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , stderr : { isTTY : false } , noColor : true } ;
77+ const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , env : { NO_COLOR : '1' } } ;
8578 const env = buildEnvironment ( ctx ) ;
8679 expect ( env . NO_COLOR ) . to . equal ( '1' ) ;
8780 } ) ;
8881 } ) ;
8982
9083 describe ( 'synthetic vars' , ( ) => {
9184 it ( 'should set COLUMNS and LINES when stdout is not a TTY' , ( ) => {
92- const ctx = { stdout : { isTTY : false , columns : 120 , rows : 40 } , stderr : { isTTY : false } , noColor : false } ;
85+ const ctx = { stdout : { isTTY : false , columns : 120 , rows : 40 } , env : { } } ;
9386 const env = buildEnvironment ( ctx ) ;
9487 expect ( env . COLUMNS ) . to . equal ( '120' ) ;
9588 expect ( env . LINES ) . to . equal ( '40' ) ;
9689 } ) ;
9790
9891 it ( 'should not set COLUMNS and LINES when stdout is a TTY' , ( ) => {
99- const ctx = { stdout : { isTTY : true , columns : 120 , rows : 40 } , stderr : { isTTY : true } , noColor : false } ;
92+ const ctx = { stdout : { isTTY : true , columns : 120 , rows : 40 } , env : { } } ;
10093 const env = buildEnvironment ( ctx ) ;
10194 expect ( env ) . to . not . have . property ( 'COLUMNS' ) ;
10295 expect ( env ) . to . not . have . property ( 'LINES' ) ;
10396 } ) ;
10497
10598 it ( 'should not synthetically set CLICOLOR_FORCE when stdout is piped' , ( ) => {
106- const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , stderr : { isTTY : true } , noColor : false } ;
99+ const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , env : { } } ;
107100 const env = buildEnvironment ( ctx ) ;
108101 // CLICOLOR_FORCE affects all streams, not just stderr.
109102 expect ( env ) . to . not . have . property ( 'CLICOLOR_FORCE' ) ;
@@ -112,29 +105,27 @@ describe('build-exec-environment', () => {
112105
113106 describe ( 'user overrides' , ( ) => {
114107 it ( 'should let user env override inherited vars' , ( ) => {
115- process . env . TERM = 'xterm' ;
116- const ctx = { stdout : { isTTY : true } , stderr : { isTTY : true } , noColor : false } ;
108+ const ctx = { stdout : { isTTY : true } , env : { TERM : 'xterm' } } ;
117109 const env = buildEnvironment ( ctx , { TERM : 'dumb' } ) ;
118110 expect ( env . TERM ) . to . equal ( 'dumb' ) ;
119111 } ) ;
120112
121113 it ( 'should let user env override synthetic vars' , ( ) => {
122- const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , stderr : { isTTY : false } , noColor : false } ;
114+ const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , env : { } } ;
123115 const env = buildEnvironment ( ctx , { COLUMNS : '200' } ) ;
124116 expect ( env . COLUMNS ) . to . equal ( '200' ) ;
125117 } ) ;
126118
127119 it ( 'should pass through arbitrary user vars' , ( ) => {
128- const ctx = { stdout : { isTTY : true } , stderr : { isTTY : true } , noColor : false } ;
120+ const ctx = { stdout : { isTTY : true } , env : { } } ;
129121 const env = buildEnvironment ( ctx , { MY_APP_VAR : 'hello' } ) ;
130122 expect ( env . MY_APP_VAR ) . to . equal ( 'hello' ) ;
131123 } ) ;
132124 } ) ;
133125
134126 describe ( 'precedence' , ( ) => {
135127 it ( 'should apply inherited < synthetic < user' , ( ) => {
136- process . env . FORCE_COLOR = '1' ;
137- const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , stderr : { isTTY : false } , noColor : false } ;
128+ const ctx = { stdout : { isTTY : false , columns : 80 , rows : 24 } , env : { FORCE_COLOR : '1' } } ;
138129 const env = buildEnvironment ( ctx , { COLUMNS : '999' , FORCE_COLOR : '3' } ) ;
139130 // User wins over synthetic
140131 expect ( env . COLUMNS ) . to . equal ( '999' ) ;
0 commit comments