@@ -117,3 +117,121 @@ test.cb("should use correct env", (t) => {
117117    t . end ( ) ; 
118118  } ) ; 
119119} ) ; 
120+ 
121+ test . serial . cb ( "should not polute BABEL_ENV after using forceEnv" ,  ( t )  =>  { 
122+   const  initialBabelEnv  =  process . env . BABEL_ENV ; 
123+ 
124+   const  config  =  { 
125+     entry : path . join ( __dirname ,  "fixtures/basic.js" ) , 
126+     output : { 
127+       path : t . context . directory , 
128+     } , 
129+     module : { 
130+       loaders : [ 
131+         { 
132+           test : / \. j s x ? / , 
133+           loader : babelLoader , 
134+           query : { 
135+             forceEnv : "testenv" , 
136+             env : { 
137+               testenv : { 
138+                 presets : [ "es2015" ] , 
139+               } , 
140+             } 
141+           } , 
142+           exclude : / n o d e _ m o d u l e s / , 
143+         } , 
144+       ] , 
145+     } , 
146+   } ; 
147+ 
148+   webpack ( config ,  ( )  =>  { 
149+     t . truthy ( process . env . BABEL_ENV  ===  initialBabelEnv ) ; 
150+     t . end ( ) ; 
151+   } ) ; 
152+ } ) ; 
153+ 
154+ test . serial . cb ( "should not polute BABEL_ENV after using forceEnv (on exception)" ,  ( t )  =>  { 
155+   const  initialBabelEnv  =  process . env . BABEL_ENV ; 
156+ 
157+   const  config  =  { 
158+     entry : path . join ( __dirname ,  "fixtures/basic.js" ) , 
159+     output : { 
160+       path : t . context . directory , 
161+     } , 
162+     module : { 
163+       loaders : [ 
164+         { 
165+           test : / \. j s x ? / , 
166+           loader : babelLoader , 
167+           query : { 
168+             forceEnv : "testenv" , 
169+             env : { 
170+               testenv : { 
171+                 presets : [ "es2015asd" ] , 
172+               } , 
173+             } 
174+           } , 
175+           exclude : / n o d e _ m o d u l e s / , 
176+         } , 
177+       ] , 
178+     } , 
179+   } ; 
180+ 
181+   webpack ( config ,  ( )  =>  { 
182+     t . truthy ( process . env . BABEL_ENV  ===  initialBabelEnv ) ; 
183+     t . end ( ) ; 
184+   } ) ; 
185+ } ) ; 
186+ 
187+ test . serial . cb ( "should not change BABEL_ENV when using forceEnv" ,  ( t )  =>  { 
188+   const  initialBabelEnv  =  process . env . BABEL_ENV ; 
189+ 
190+   process . env . BABEL_ENV  =  "nontestenv" ; 
191+ 
192+   const  config  =  { 
193+     entry : path . join ( __dirname ,  "fixtures/basic.js" ) , 
194+     output : { 
195+       path : t . context . directory , 
196+     } , 
197+     module : { 
198+       loaders : [ 
199+         { 
200+           test : / \. j s x ? / , 
201+           loader : babelLoader , 
202+           query : { 
203+             forceEnv : "testenv" , 
204+             env : { 
205+               testenv : { 
206+                 presets : [ "es2015abc" ] , 
207+               } , 
208+               nontestenv : { 
209+                 presets : [ "es2015xzy" ] 
210+               } 
211+             } 
212+           } , 
213+           exclude : / n o d e _ m o d u l e s / , 
214+         } , 
215+       ] , 
216+     } , 
217+   } ; 
218+ 
219+   webpack ( config ,  ( err ,  stats )  =>  { 
220+     t . is ( err ,  null ) ; 
221+ 
222+     t . true ( stats . compilation . errors . length  ===  1 ) ; 
223+ 
224+     t . truthy ( stats . compilation . errors [ 0 ] . message . match ( / e s 2 0 1 5 a b c / ) ) ; 
225+     t . falsy ( stats . compilation . errors [ 0 ] . message . match ( / e s 2 0 1 5 x y z / ) ) ; 
226+ 
227+     t . truthy ( "nontestenv"  ===  process . env . BABEL_ENV ) ; 
228+ 
229+     if  ( initialBabelEnv  !==  undefined )  { 
230+       process . env . BABEL_ENV  =  initialBabelEnv ; 
231+     }  else  { 
232+       delete  process . env . BABEL_ENV ; 
233+     } 
234+ 
235+     t . end ( ) ; 
236+   } ) ; 
237+ } ) ; 
0 commit comments