@@ -4,7 +4,7 @@ import { describe, it } from 'node:test';
44import { render , screen } from '@testing-library/react' ;
55
66describe ( 'ErrorPage' , ( ) => {
7- it ( 'renders technical details in preview environments' , async t => {
7+ const setupErrorPage = async ( t , showErrorDetails , suffix = '' ) => {
88 t . mock . module ( '#site/components/Common/Button' , {
99 defaultExport : ( { children, href } ) => < a href = { href } > { children } </ a > ,
1010 } ) ;
@@ -15,11 +15,15 @@ describe('ErrorPage', () => {
1515
1616 t . mock . module ( '#site/next.constants.mjs' , {
1717 namedExports : {
18- SHOW_ERROR_DETAILS : true ,
18+ SHOW_ERROR_DETAILS : showErrorDetails ,
1919 } ,
2020 } ) ;
2121
22- const { default : ErrorPage } = await import ( '../app/[locale]/error.tsx' ) ;
22+ return import ( `../app/[locale]/error.tsx${ suffix } ` ) ;
23+ } ;
24+
25+ it ( 'renders technical details in preview environments' , async t => {
26+ const { default : ErrorPage } = await setupErrorPage ( t , true ) ;
2327
2428 render (
2529 < ErrorPage
@@ -38,8 +42,8 @@ describe('ErrorPage', () => {
3842 'layouts.error.backToHome'
3943 ) ;
4044 assert . equal (
41- screen . getByText ( 'components.downloadReleasesTable .details' ) . textContent ,
42- 'components.downloadReleasesTable .details'
45+ screen . getByText ( 'layouts.error .details' ) . textContent ,
46+ 'layouts.error .details'
4347 ) ;
4448 assert . match (
4549 screen . getByText ( / P r e v i e w d e p l o y m e n t f a i l e d / ) . textContent ,
@@ -50,4 +54,24 @@ describe('ErrorPage', () => {
5054 / d i g e s t : a b c 1 2 3 / i
5155 ) ;
5256 } ) ;
57+
58+ it ( 'hides technical details when the flag is disabled' , async t => {
59+ const { default : ErrorPage } = await setupErrorPage (
60+ t ,
61+ false ,
62+ '?show-error-details-disabled'
63+ ) ;
64+
65+ render (
66+ < ErrorPage
67+ error = { Object . assign ( new Error ( 'Production should stay generic' ) , {
68+ digest : 'hidden123' ,
69+ } ) }
70+ />
71+ ) ;
72+
73+ assert . equal ( screen . queryByText ( 'layouts.error.details' ) , null ) ;
74+ assert . equal ( screen . queryByText ( / P r o d u c t i o n s h o u l d s t a y g e n e r i c / ) , null ) ;
75+ assert . equal ( screen . queryByText ( / d i g e s t : h i d d e n 1 2 3 / i) , null ) ;
76+ } ) ;
5377} ) ;
0 commit comments