@@ -140,6 +140,23 @@ describe("proxy option", () => {
140140 let proxyServer1 ;
141141 let proxyServer2 ;
142142
143+ function getStderrOutput ( stderrSpy ) {
144+ return stderrSpy . mock . calls
145+ . map ( ( call ) => call [ 0 ] )
146+ . filter ( ( output ) => ! output . includes ( "DeprecationWarning" ) )
147+ . join ( "" )
148+ . replaceAll ( / 1 2 7 \. 0 \. 0 \. 1 : \d + / g, "127.0.0.1:<port>" )
149+ . replaceAll ( / \[ E N O T F O U N D \] | \[ E A I _ A G A I N \] / g, "[<DNS_ERROR>]" ) ;
150+ }
151+
152+ function getConsoleErrorOutput ( consoleSpy ) {
153+ return consoleSpy . mock . calls
154+ . map ( ( call ) => call [ 0 ] )
155+ . join ( "\n" )
156+ . replaceAll ( / 1 2 7 \. 0 \. 0 \. 1 : \d + / g, "127.0.0.1:<port>" )
157+ . replaceAll ( / \[ E N O T F O U N D \] | \[ E A I _ A G A I N \] / g, "[<DNS_ERROR>]" ) ;
158+ }
159+
143160 async function listenProxyServers ( ) {
144161 const proxyApp1 = express ( ) ;
145162 const proxyApp2 = express ( ) ;
@@ -834,16 +851,10 @@ describe("proxy option", () => {
834851 describe ( "should work and respect `logger` option" , ( ) => {
835852 let server ;
836853 let req ;
837- let customLogProvider ;
854+ let consoleSpy ;
838855
839856 beforeAll ( async ( ) => {
840- customLogProvider = {
841- log : jest . fn ( ) ,
842- debug : jest . fn ( ) ,
843- info : jest . fn ( ) ,
844- warn : jest . fn ( ) ,
845- error : jest . fn ( ) ,
846- } ;
857+ consoleSpy = jest . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
847858
848859 const compiler = webpack ( [ config , config ] ) ;
849860
@@ -853,7 +864,7 @@ describe("proxy option", () => {
853864 {
854865 context : "/my-path" ,
855866 target : "http://unknown:1234" ,
856- logger : customLogProvider ,
867+ logger : console ,
857868 } ,
858869 ] ,
859870 port : port3 ,
@@ -869,6 +880,7 @@ describe("proxy option", () => {
869880 } ) ;
870881
871882 afterAll ( async ( ) => {
883+ consoleSpy . mockRestore ( ) ;
872884 await server . stop ( ) ;
873885 await closeProxyServers ( ) ;
874886 } ) ;
@@ -877,28 +889,24 @@ describe("proxy option", () => {
877889 it ( "respects a proxy option when a request path is matched" , async ( ) => {
878890 await req . get ( "/my-path" ) ;
879891
880- expect ( customLogProvider . error ) . toHaveBeenCalledTimes ( 1 ) ;
892+ expect ( getConsoleErrorOutput ( consoleSpy ) ) . toMatchSnapshot ( ) ;
881893 } ) ;
882894 } ) ;
883895 } ) ;
884896
885897 describe ( "should work and respect the `infrastructureLogging.level` option" , ( ) => {
886898 let server ;
887899 let req ;
888- let customLogProvider ;
900+ let stderrSpy ;
889901
890902 beforeAll ( async ( ) => {
891- customLogProvider = {
892- log : jest . fn ( ) ,
893- debug : jest . fn ( ) ,
894- info : jest . fn ( ) ,
895- warn : jest . fn ( ) ,
896- error : jest . fn ( ) ,
897- } ;
903+ stderrSpy = jest
904+ . spyOn ( process . stderr , "write" )
905+ . mockImplementation ( ( ) => true ) ;
898906
899907 const compiler = webpack ( {
900908 ...config ,
901- infrastructureLogging : { level : "error" } ,
909+ infrastructureLogging : { colors : false , level : "error" } ,
902910 } ) ;
903911
904912 server = new Server (
@@ -907,7 +915,6 @@ describe("proxy option", () => {
907915 {
908916 context : "/my-path" ,
909917 target : "http://unknown:1234" ,
910- logger : customLogProvider ,
911918 } ,
912919 ] ,
913920 port : port3 ,
@@ -923,6 +930,7 @@ describe("proxy option", () => {
923930 } ) ;
924931
925932 afterAll ( async ( ) => {
933+ stderrSpy . mockRestore ( ) ;
926934 await server . stop ( ) ;
927935 await closeProxyServers ( ) ;
928936 } ) ;
@@ -931,24 +939,20 @@ describe("proxy option", () => {
931939 it ( "respects a proxy option when a request path is matched" , async ( ) => {
932940 await req . get ( "/my-path" ) ;
933941
934- expect ( customLogProvider . error ) . toHaveBeenCalledTimes ( 1 ) ;
942+ expect ( getStderrOutput ( stderrSpy ) ) . toMatchSnapshot ( ) ;
935943 } ) ;
936944 } ) ;
937945 } ) ;
938946
939947 describe ( "should work and respect the `infrastructureLogging.level` option with `none` value" , ( ) => {
940948 let server ;
941949 let req ;
942- let customLogProvider ;
950+ let stderrSpy ;
943951
944952 beforeAll ( async ( ) => {
945- customLogProvider = {
946- log : jest . fn ( ) ,
947- debug : jest . fn ( ) ,
948- info : jest . fn ( ) ,
949- warn : jest . fn ( ) ,
950- error : jest . fn ( ) ,
951- } ;
953+ stderrSpy = jest
954+ . spyOn ( process . stderr , "write" )
955+ . mockImplementation ( ( ) => true ) ;
952956
953957 const compiler = webpack ( {
954958 ...config ,
@@ -961,7 +965,6 @@ describe("proxy option", () => {
961965 {
962966 context : "/my-path" ,
963967 target : "http://unknown:1234" ,
964- logger : customLogProvider ,
965968 } ,
966969 ] ,
967970 port : port3 ,
@@ -975,14 +978,15 @@ describe("proxy option", () => {
975978 } ) ;
976979
977980 afterAll ( async ( ) => {
981+ stderrSpy . mockRestore ( ) ;
978982 await server . stop ( ) ;
979983 } ) ;
980984
981985 describe ( "target" , ( ) => {
982986 it ( "respects a proxy option when a request path is matched" , async ( ) => {
983987 await req . get ( "/my-path" ) ;
984988
985- expect ( customLogProvider . error ) . toHaveBeenCalledTimes ( 0 ) ;
989+ expect ( getStderrOutput ( stderrSpy ) ) . toMatchSnapshot ( ) ;
986990 } ) ;
987991 } ) ;
988992 } ) ;
0 commit comments