@@ -256,6 +256,58 @@ testMatrix.forEach(({ args }) => {
256256 } )
257257 } )
258258
259+ test ( testName ( '[context.dev.environment] should override [build.environment]' , args ) , async ( t ) => {
260+ await withSiteBuilder ( 'site-with-build-environment' , async ( builder ) => {
261+ builder
262+ . withNetlifyToml ( {
263+ config : {
264+ build : { environment : { TEST : 'DEFAULT_CONTEXT' } , functions : 'functions' } ,
265+ context : { dev : { environment : { TEST : 'DEV_CONTEXT' } } } ,
266+ } ,
267+ } )
268+ . withFunction ( {
269+ path : 'env.js' ,
270+ handler : async ( ) => ( {
271+ statusCode : 200 ,
272+ body : `${ process . env . TEST } ` ,
273+ } ) ,
274+ } )
275+
276+ await builder . buildAsync ( )
277+
278+ await withDevServer ( { cwd : builder . directory , args } , async ( server ) => {
279+ const response = await got ( `${ server . url } /.netlify/functions/env` ) . text ( )
280+ t . is ( response , 'DEV_CONTEXT' )
281+ } )
282+ } )
283+ } )
284+
285+ test ( testName ( 'should use [build.environment] and not [context.production.environment]' , args ) , async ( t ) => {
286+ await withSiteBuilder ( 'site-with-build-environment' , async ( builder ) => {
287+ builder
288+ . withNetlifyToml ( {
289+ config : {
290+ build : { environment : { TEST : 'DEFAULT_CONTEXT' } , functions : 'functions' } ,
291+ context : { production : { environment : { TEST : 'PRODUCTION_CONTEXT' } } } ,
292+ } ,
293+ } )
294+ . withFunction ( {
295+ path : 'env.js' ,
296+ handler : async ( ) => ( {
297+ statusCode : 200 ,
298+ body : `${ process . env . TEST } ` ,
299+ } ) ,
300+ } )
301+
302+ await builder . buildAsync ( )
303+
304+ await withDevServer ( { cwd : builder . directory , args } , async ( server ) => {
305+ const response = await got ( `${ server . url } /.netlify/functions/env` ) . text ( )
306+ t . is ( response , 'DEFAULT_CONTEXT' )
307+ } )
308+ } )
309+ } )
310+
259311 test ( testName ( 'should override .env.development with process env' , args ) , async ( t ) => {
260312 await withSiteBuilder ( 'site-with-override' , async ( builder ) => {
261313 builder
@@ -321,7 +373,7 @@ testMatrix.forEach(({ args }) => {
321373 } )
322374 } )
323375
324- test ( testName ( 'should override value of the CONTEXT env variable' , args ) , async ( t ) => {
376+ test ( testName ( 'should set value of the CONTEXT env variable' , args ) , async ( t ) => {
325377 await withSiteBuilder ( 'site-with-context-override' , async ( builder ) => {
326378 builder . withNetlifyToml ( { config : { build : { functions : 'functions' } } } ) . withFunction ( {
327379 path : 'env.js' ,
@@ -333,7 +385,7 @@ testMatrix.forEach(({ args }) => {
333385
334386 await builder . buildAsync ( )
335387
336- await withDevServer ( { cwd : builder . directory , env : { CONTEXT : 'production' } , args } , async ( server ) => {
388+ await withDevServer ( { cwd : builder . directory , args } , async ( server ) => {
337389 const response = await got ( `${ server . url } /.netlify/functions/env` ) . text ( )
338390 t . is ( response , 'dev' )
339391 } )
0 commit comments