File tree Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,7 @@ var overlay =
216216		: { 
217217				send : function  send ( )  { } 
218218			} ; 
219+ /* Rspack dev server runtime client */ 
219220var  onSocketMessage  =  { 
220221	hot : function  hot ( )  { 
221222		if  ( parsedResourceQuery . hot  ===  "false" )  { 
Original file line number Diff line number Diff line change 1+ const  Module  =  require ( "module" ) ; 
2+ const  MODULE_MAP : Record < string ,  typeof  Module . _resolveFilename >  =  { } ; 
13const  RESOLVER_MAP : Record < string ,  typeof  require . resolve >  =  { } ; 
24export  const  addResolveAlias  =  ( 
35	name : string , 
@@ -18,6 +20,13 @@ export const addResolveAlias = (
1820			id , 
1921			options 
2022		] ) )  as  typeof  require . resolve ; 
23+ 	MODULE_MAP [ modulePath ]  =  Module . _resolveFilename ; 
24+ 	Module . _resolveFilename  =  Module . _resolveFilename  =  ( request : string ,  mod : NodeModule ,  ...args : unknown [ ] )  =>  { 
25+ 			if  ( mod . filename  ===  modulePath  &&  aliasMap [ request ] )  { 
26+ 				return  aliasMap [ request ] ; 
27+ 			} 
28+ 			return  MODULE_MAP [ modulePath ] ( request ,  mod ,  ...args ) ; 
29+ 	} ; 
2130} ; 
2231
2332export  const  removeResolveAlias  =  ( name : string )  =>  { 
@@ -30,6 +39,7 @@ export const removeResolveAlias = (name: string) => {
3039		throw  new  Error ( "Failed to resolve webpack-dev-server" ) ; 
3140	} 
3241	if  ( RESOLVER_MAP [ modulePath ] )  { 
42+ 		Module . _resolveFilename  =  RESOLVER_MAP [ modulePath ] ! ; 
3343		m . require . resolve  =  RESOLVER_MAP [ modulePath ] ! ; 
3444		delete  RESOLVER_MAP [ modulePath ] ; 
3545	} 
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ exports[`client option configure client entry should disable client entry: page
66
77exports[`client option configure client entry should disable client entry: response status 1`] = `200`;
88
9+ exports[`client option configure client entry should redirect client entry to rspack: console messages 1`] = `[]`;
10+ 
11+ exports[`client option configure client entry should redirect client entry to rspack: page errors 1`] = `[]`;
12+ 
13+ exports[`client option configure client entry should redirect client entry to rspack: response status 1`] = `200`;
14+ 
915exports[`client option default behaviour responds with a 200 status code for /ws path: console messages 1`] = `[]`;
1016
1117exports[`client option default behaviour responds with a 200 status code for /ws path: page errors 1`] = `[]`;
Original file line number Diff line number Diff line change @@ -193,6 +193,66 @@ describe("client option", () => {
193193		} ) ; 
194194	} ) ; 
195195
196+ 	describe ( "configure client entry" ,  ( )  =>  { 
197+ 		let  compiler ; 
198+ 		let  server ; 
199+ 		let  page ; 
200+ 		let  browser ; 
201+ 		let  pageErrors ; 
202+ 		let  consoleMessages ; 
203+ 
204+ 		beforeEach ( async  ( )  =>  { 
205+ 			compiler  =  webpack ( { 
206+ 				...config , 
207+ 				devtool : false 
208+ 			} ) ; 
209+ 
210+ 			server  =  new  Server ( 
211+ 				{ 
212+ 					port
213+ 				} , 
214+ 				compiler 
215+ 			) ; 
216+ 
217+ 			await  server . start ( ) ; 
218+ 
219+ 			( {  page,  browser }  =  await  runBrowser ( ) ) ; 
220+ 
221+ 			pageErrors  =  [ ] ; 
222+ 			consoleMessages  =  [ ] ; 
223+ 		} ) ; 
224+ 
225+ 		afterEach ( async  ( )  =>  { 
226+ 			await  browser . close ( ) ; 
227+ 			await  server . stop ( ) ; 
228+ 		} ) ; 
229+ 
230+ 		it ( "should redirect client entry to rspack" ,  async  ( )  =>  { 
231+ 			page 
232+ 				. on ( "console" ,  message  =>  { 
233+ 					consoleMessages . push ( message ) ; 
234+ 				} ) 
235+ 				. on ( "pageerror" ,  error  =>  { 
236+ 					pageErrors . push ( error ) ; 
237+ 				} ) ; 
238+ 
239+ 			const  response  =  await  page . goto ( `http://127.0.0.1:${ port }  /main.js` ,  { 
240+ 				waitUntil : "networkidle0" 
241+ 			} ) ; 
242+ 
243+ 			expect ( await  response . text ( ) ) . toContain ( "/* Rspack dev server runtime client */" ) 
244+ 
245+ 			expect ( response . status ( ) ) . toMatchSnapshot ( "response status" ) ; 
246+ 
247+ 			expect ( consoleMessages . map ( message  =>  message . text ( ) ) ) . toMatchSnapshot ( 
248+ 				"console messages" 
249+ 			) ; 
250+ 
251+ 			expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ; 
252+ 		} ) ; 
253+ 	} ) ; 
254+ 
255+ 
196256	describe ( "webSocketTransport" ,  ( )  =>  { 
197257		const  clientModes  =  [ 
198258			{ 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments