@@ -117,7 +117,42 @@ test.cb("should use correct env", (t) => {
117117 } ) ;
118118} ) ;
119119
120- test . cb ( "should not throw without config" , ( t ) => {
120+ test . serial . cb ( "should not polute BABEL_ENV after using forceEnv" , ( t ) => {
121+ const initialBabelEnv = process . env . BABEL_ENV ;
122+
123+ const config = {
124+ entry : path . join ( __dirname , "fixtures/basic.js" ) ,
125+ output : {
126+ path : t . context . directory ,
127+ } ,
128+ module : {
129+ loaders : [
130+ {
131+ test : / \. j s x ? / ,
132+ loader : babelLoader ,
133+ query : {
134+ forceEnv : "testenv" ,
135+ env : {
136+ testenv : {
137+ presets : [ "es2015" ] ,
138+ } ,
139+ }
140+ } ,
141+ exclude : / n o d e _ m o d u l e s / ,
142+ } ,
143+ ] ,
144+ } ,
145+ } ;
146+
147+ webpack ( config , ( ) => {
148+ t . truthy ( process . env . BABEL_ENV === initialBabelEnv ) ;
149+ t . end ( ) ;
150+ } ) ;
151+ } ) ;
152+
153+ test . serial . cb ( "should not polute BABEL_ENV after using forceEnv (on exception)" , ( t ) => {
154+ const initialBabelEnv = process . env . BABEL_ENV ;
155+
121156 const config = {
122157 entry : path . join ( __dirname , "fixtures/basic.js" ) ,
123158 output : {
@@ -128,6 +163,52 @@ test.cb("should not throw without config", (t) => {
128163 {
129164 test : / \. j s x ? / ,
130165 loader : babelLoader ,
166+ query : {
167+ forceEnv : "testenv" ,
168+ env : {
169+ testenv : {
170+ presets : [ "es2015asd" ] ,
171+ } ,
172+ }
173+ } ,
174+ exclude : / n o d e _ m o d u l e s / ,
175+ } ,
176+ ] ,
177+ } ,
178+ } ;
179+
180+ webpack ( config , ( ) => {
181+ t . truthy ( process . env . BABEL_ENV === initialBabelEnv ) ;
182+ t . end ( ) ;
183+ } ) ;
184+ } ) ;
185+
186+ test . serial . cb ( "should not change BABEL_ENV when using forceEnv" , ( t ) => {
187+ const initialBabelEnv = process . env . BABEL_ENV ;
188+
189+ process . env . BABEL_ENV = "nontestenv" ;
190+
191+ const config = {
192+ entry : path . join ( __dirname , "fixtures/basic.js" ) ,
193+ output : {
194+ path : t . context . directory ,
195+ } ,
196+ module : {
197+ loaders : [
198+ {
199+ test : / \. j s x ? / ,
200+ loader : babelLoader ,
201+ query : {
202+ forceEnv : "testenv" ,
203+ env : {
204+ testenv : {
205+ presets : [ "es2015abc" ] ,
206+ } ,
207+ nontestenv : {
208+ presets : [ "es2015xzy" ]
209+ }
210+ }
211+ } ,
131212 exclude : / n o d e _ m o d u l e s / ,
132213 } ,
133214 ] ,
@@ -137,8 +218,43 @@ test.cb("should not throw without config", (t) => {
137218 webpack ( config , ( err , stats ) => {
138219 t . is ( err , null ) ;
139220
140- t . true ( stats . compilation . errors . length === 0 ) ;
221+ t . true ( stats . compilation . errors . length === 1 ) ;
222+
223+ t . truthy ( stats . compilation . errors [ 0 ] . message . match ( / e s 2 0 1 5 a b c / ) ) ;
224+ t . falsy ( stats . compilation . errors [ 0 ] . message . match ( / e s 2 0 1 5 x y z / ) ) ;
225+
226+ t . truthy ( "nontestenv" === process . env . BABEL_ENV ) ;
227+
228+ if ( initialBabelEnv !== undefined ) {
229+ process . env . BABEL_ENV = initialBabelEnv ;
230+ } else {
231+ delete process . env . BABEL_ENV ;
232+ }
141233
142234 t . end ( ) ;
143235 } ) ;
144236} ) ;
237+
238+ test . cb ( "should not throw without config" , ( t ) => {
239+ const config = {
240+ entry : path . join ( __dirname , "fixtures/basic.js" ) ,
241+ output : {
242+ path : t . context . directory ,
243+ } ,
244+ module : {
245+ loaders : [
246+ {
247+ test : / \. j s x ? / ,
248+ loader : babelLoader ,
249+ exclude : / n o d e _ m o d u l e s / ,
250+ } ,
251+ ] ,
252+ } ,
253+ } ;
254+
255+ webpack ( config , ( err , stats ) => {
256+ t . is ( err , null ) ;
257+ t . true ( stats . compilation . errors . length === 0 ) ;
258+ t . end ( ) ;
259+ } ) ;
260+ } ) ;
0 commit comments