@@ -5,6 +5,7 @@ const path = require('path')
55const avaTest = require ( 'ava' )
66const { isCI } = require ( 'ci-info' )
77const dotProp = require ( 'dot-prop' )
8+ const getAvailablePort = require ( 'get-port' )
89const jwt = require ( 'jsonwebtoken' )
910const { Response } = require ( 'node-fetch' )
1011
@@ -964,3 +965,122 @@ test('should have only allowed environment variables set', async (t) => {
964965 } )
965966 } )
966967} )
968+
969+ test ( 'should inject the `NETLIFY_DEV` environment variable in the process (legacy environment variables)' , async ( t ) => {
970+ const externalServerPort = await getAvailablePort ( )
971+ const externalServerPath = path . join ( __dirname , 'utils' , 'external-server-cli.cjs' )
972+ const command = `node ${ externalServerPath } ${ externalServerPort } `
973+
974+ await withSiteBuilder ( 'site-with-legacy-env-vars' , async ( builder ) => {
975+ const publicDir = 'public'
976+
977+ await builder
978+ . withNetlifyToml ( {
979+ config : {
980+ build : {
981+ publish : publicDir ,
982+ } ,
983+ dev : {
984+ command,
985+ publish : publicDir ,
986+ targetPort : externalServerPort ,
987+ framework : '#custom' ,
988+ } ,
989+ } ,
990+ } )
991+ . buildAsync ( )
992+
993+ await withDevServer ( { cwd : builder . directory } , async ( { port } ) => {
994+ const response = await got ( `http://localhost:${ port } /` ) . json ( )
995+
996+ t . is ( response . env . NETLIFY_DEV , 'true' )
997+ } )
998+ } )
999+ } )
1000+
1001+ test ( 'should inject the `NETLIFY_DEV` environment variable in the process' , async ( t ) => {
1002+ const siteInfo = {
1003+ account_slug : 'test-account' ,
1004+ build_settings : {
1005+ env : { } ,
1006+ } ,
1007+ id : 'site_id' ,
1008+ name : 'site-name' ,
1009+ use_envelope : true ,
1010+ }
1011+ const existingVar = {
1012+ key : 'EXISTING_VAR' ,
1013+ scopes : [ 'builds' , 'functions' ] ,
1014+ values : [
1015+ {
1016+ id : '1234' ,
1017+ context : 'production' ,
1018+ value : 'envelope-prod-value' ,
1019+ } ,
1020+ {
1021+ id : '2345' ,
1022+ context : 'dev' ,
1023+ value : 'envelope-dev-value' ,
1024+ } ,
1025+ ] ,
1026+ }
1027+ const routes = [
1028+ { path : 'sites/site_id' , response : siteInfo } ,
1029+ { path : 'sites/site_id/service-instances' , response : [ ] } ,
1030+ {
1031+ path : 'accounts' ,
1032+ response : [ { slug : siteInfo . account_slug } ] ,
1033+ } ,
1034+ {
1035+ path : 'accounts/test-account/env/EXISTING_VAR' ,
1036+ response : existingVar ,
1037+ } ,
1038+ {
1039+ path : 'accounts/test-account/env' ,
1040+ response : [ existingVar ] ,
1041+ } ,
1042+ ]
1043+
1044+ const externalServerPort = await getAvailablePort ( )
1045+ const externalServerPath = path . join ( __dirname , 'utils' , 'external-server-cli.cjs' )
1046+ const command = `node ${ externalServerPath } ${ externalServerPort } `
1047+
1048+ await withSiteBuilder ( 'site-with-env-vars' , async ( builder ) => {
1049+ const publicDir = 'public'
1050+
1051+ await builder
1052+ . withNetlifyToml ( {
1053+ config : {
1054+ build : {
1055+ publish : publicDir ,
1056+ } ,
1057+ dev : {
1058+ command,
1059+ publish : publicDir ,
1060+ targetPort : externalServerPort ,
1061+ framework : '#custom' ,
1062+ } ,
1063+ } ,
1064+ } )
1065+ . buildAsync ( )
1066+
1067+ await withMockApi ( routes , async ( { apiUrl } ) => {
1068+ await withDevServer (
1069+ {
1070+ cwd : builder . directory ,
1071+ offline : false ,
1072+ env : {
1073+ NETLIFY_API_URL : apiUrl ,
1074+ NETLIFY_SITE_ID : 'site_id' ,
1075+ NETLIFY_AUTH_TOKEN : 'fake-token' ,
1076+ } ,
1077+ } ,
1078+ async ( { port } ) => {
1079+ const response = await got ( `http://localhost:${ port } /` ) . json ( )
1080+
1081+ t . is ( response . env . NETLIFY_DEV , 'true' )
1082+ } ,
1083+ )
1084+ } )
1085+ } )
1086+ } )
0 commit comments