@@ -140,6 +140,21 @@ 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+ }
150+
151+ function getConsoleErrorOutput ( consoleSpy ) {
152+ return consoleSpy . mock . calls
153+ . map ( ( call ) => call [ 0 ] )
154+ . join ( "\n" )
155+ . replaceAll ( / 1 2 7 \. 0 \. 0 \. 1 : \d + / g, "127.0.0.1:<port>" ) ;
156+ }
157+
143158 async function listenProxyServers ( ) {
144159 const proxyApp1 = express ( ) ;
145160 const proxyApp2 = express ( ) ;
@@ -834,16 +849,10 @@ describe("proxy option", () => {
834849 describe ( "should work and respect `logger` option" , ( ) => {
835850 let server ;
836851 let req ;
837- let customLogProvider ;
852+ let consoleSpy ;
838853
839854 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- } ;
855+ consoleSpy = jest . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
847856
848857 const compiler = webpack ( [ config , config ] ) ;
849858
@@ -853,7 +862,7 @@ describe("proxy option", () => {
853862 {
854863 context : "/my-path" ,
855864 target : "http://unknown:1234" ,
856- logger : customLogProvider ,
865+ logger : console ,
857866 } ,
858867 ] ,
859868 port : port3 ,
@@ -869,6 +878,7 @@ describe("proxy option", () => {
869878 } ) ;
870879
871880 afterAll ( async ( ) => {
881+ consoleSpy . mockRestore ( ) ;
872882 await server . stop ( ) ;
873883 await closeProxyServers ( ) ;
874884 } ) ;
@@ -877,28 +887,24 @@ describe("proxy option", () => {
877887 it ( "respects a proxy option when a request path is matched" , async ( ) => {
878888 await req . get ( "/my-path" ) ;
879889
880- expect ( customLogProvider . error ) . toHaveBeenCalledTimes ( 1 ) ;
890+ expect ( getConsoleErrorOutput ( consoleSpy ) ) . toMatchSnapshot ( ) ;
881891 } ) ;
882892 } ) ;
883893 } ) ;
884894
885895 describe ( "should work and respect the `infrastructureLogging.level` option" , ( ) => {
886896 let server ;
887897 let req ;
888- let customLogProvider ;
898+ let stderrSpy ;
889899
890900 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- } ;
901+ stderrSpy = jest
902+ . spyOn ( process . stderr , "write" )
903+ . mockImplementation ( ( ) => true ) ;
898904
899905 const compiler = webpack ( {
900906 ...config ,
901- infrastructureLogging : { level : "error" } ,
907+ infrastructureLogging : { colors : false , level : "error" } ,
902908 } ) ;
903909
904910 server = new Server (
@@ -907,7 +913,6 @@ describe("proxy option", () => {
907913 {
908914 context : "/my-path" ,
909915 target : "http://unknown:1234" ,
910- logger : customLogProvider ,
911916 } ,
912917 ] ,
913918 port : port3 ,
@@ -923,6 +928,7 @@ describe("proxy option", () => {
923928 } ) ;
924929
925930 afterAll ( async ( ) => {
931+ stderrSpy . mockRestore ( ) ;
926932 await server . stop ( ) ;
927933 await closeProxyServers ( ) ;
928934 } ) ;
@@ -931,24 +937,20 @@ describe("proxy option", () => {
931937 it ( "respects a proxy option when a request path is matched" , async ( ) => {
932938 await req . get ( "/my-path" ) ;
933939
934- expect ( customLogProvider . error ) . toHaveBeenCalledTimes ( 1 ) ;
940+ expect ( getStderrOutput ( stderrSpy ) ) . toMatchSnapshot ( ) ;
935941 } ) ;
936942 } ) ;
937943 } ) ;
938944
939945 describe ( "should work and respect the `infrastructureLogging.level` option with `none` value" , ( ) => {
940946 let server ;
941947 let req ;
942- let customLogProvider ;
948+ let stderrSpy ;
943949
944950 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- } ;
951+ stderrSpy = jest
952+ . spyOn ( process . stderr , "write" )
953+ . mockImplementation ( ( ) => true ) ;
952954
953955 const compiler = webpack ( {
954956 ...config ,
@@ -961,7 +963,6 @@ describe("proxy option", () => {
961963 {
962964 context : "/my-path" ,
963965 target : "http://unknown:1234" ,
964- logger : customLogProvider ,
965966 } ,
966967 ] ,
967968 port : port3 ,
@@ -975,14 +976,15 @@ describe("proxy option", () => {
975976 } ) ;
976977
977978 afterAll ( async ( ) => {
979+ stderrSpy . mockRestore ( ) ;
978980 await server . stop ( ) ;
979981 } ) ;
980982
981983 describe ( "target" , ( ) => {
982984 it ( "respects a proxy option when a request path is matched" , async ( ) => {
983985 await req . get ( "/my-path" ) ;
984986
985- expect ( customLogProvider . error ) . toHaveBeenCalledTimes ( 0 ) ;
987+ expect ( getStderrOutput ( stderrSpy ) ) . toMatchSnapshot ( ) ;
986988 } ) ;
987989 } ) ;
988990 } ) ;
0 commit comments