@@ -174,6 +174,62 @@ describe("cli", () => {
174174 expect ( exitCode ) . not . toBe ( 0 ) ;
175175 expect ( stderr ) . toMatch ( / s t a t i c / i) ;
176176 } ) ;
177+
178+ it ( "NODE_ENV=production (no --prod) suppresses the stack-trace error page" , async ( ) => {
179+ const port = await getRandomPort ( "localhost" ) ;
180+ const child = runCli ( [ "--entry" , entryFile , "--port" , String ( port ) ] , {
181+ env : { NODE_ENV : "production" } ,
182+ } ) ;
183+ let result : any ;
184+ try {
185+ await waitForPort ( port , { host : "localhost" , delay : 50 , retries : 100 } ) ;
186+ const res = await fetch ( `http://localhost:${ port } /boom` ) ;
187+ expect ( res . status ) . toBe ( 500 ) ;
188+ const body = await res . text ( ) ;
189+ expect ( body ) . toContain ( "Something went wrong" ) ;
190+ expect ( body ) . not . toContain ( "BOOM_SECRET" ) ;
191+ expect ( body ) . not . toMatch ( / \n \s + a t \s / ) ; // no stack-trace frames
192+ } finally {
193+ child . kill ( "SIGTERM" ) ;
194+ result = await child . catch ( ( error : any ) => error ) ;
195+ }
196+ // NODE_ENV also drives the rest of prod mode (banner, .env.production, no watch)
197+ expect ( result . stdout ) . toContain ( "prod" ) ;
198+ } ) ;
199+
200+ it ( "--prod suppresses the stack-trace error page" , async ( ) => {
201+ const port = await getRandomPort ( "localhost" ) ;
202+ const child = runCli ( [ "--prod" , "--entry" , entryFile , "--port" , String ( port ) ] ) ;
203+ try {
204+ await waitForPort ( port , { host : "localhost" , delay : 50 , retries : 100 } ) ;
205+ const res = await fetch ( `http://localhost:${ port } /boom` ) ;
206+ expect ( res . status ) . toBe ( 500 ) ;
207+ const body = await res . text ( ) ;
208+ expect ( body ) . toContain ( "Something went wrong" ) ;
209+ expect ( body ) . not . toContain ( "BOOM_SECRET" ) ;
210+ expect ( body ) . not . toMatch ( / \n \s + a t \s / ) ; // no stack-trace frames
211+ } finally {
212+ child . kill ( "SIGTERM" ) ;
213+ await child . catch ( ( ) => { } ) ;
214+ }
215+ } ) ;
216+
217+ it ( "dev mode still shows the stack trace" , async ( ) => {
218+ const port = await getRandomPort ( "localhost" ) ;
219+ const child = runCli ( [ "--entry" , entryFile , "--port" , String ( port ) ] , {
220+ env : { NODE_ENV : "development" } ,
221+ } ) ;
222+ try {
223+ await waitForPort ( port , { host : "localhost" , delay : 50 , retries : 100 } ) ;
224+ const res = await fetch ( `http://localhost:${ port } /boom` ) ;
225+ expect ( res . status ) . toBe ( 500 ) ;
226+ const body = await res . text ( ) ;
227+ expect ( body ) . toContain ( "BOOM_SECRET" ) ;
228+ } finally {
229+ child . kill ( "SIGTERM" ) ;
230+ await child . catch ( ( ) => { } ) ;
231+ }
232+ } ) ;
177233 } ) ;
178234
179235 describe ( "errors" , ( ) => {
0 commit comments