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 =
216
216
: {
217
217
send : function send ( ) { }
218
218
} ;
219
+ /* Rspack dev server runtime client */
219
220
var onSocketMessage = {
220
221
hot : function hot ( ) {
221
222
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 > = { } ;
1
3
const RESOLVER_MAP : Record < string , typeof require . resolve > = { } ;
2
4
export const addResolveAlias = (
3
5
name : string ,
@@ -18,6 +20,13 @@ export const addResolveAlias = (
18
20
id ,
19
21
options
20
22
] ) ) 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
+ } ;
21
30
} ;
22
31
23
32
export const removeResolveAlias = ( name : string ) => {
@@ -30,6 +39,7 @@ export const removeResolveAlias = (name: string) => {
30
39
throw new Error ( "Failed to resolve webpack-dev-server" ) ;
31
40
}
32
41
if ( RESOLVER_MAP [ modulePath ] ) {
42
+ Module . _resolveFilename = RESOLVER_MAP [ modulePath ] ! ;
33
43
m . require . resolve = RESOLVER_MAP [ modulePath ] ! ;
34
44
delete RESOLVER_MAP [ modulePath ] ;
35
45
}
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
6
6
7
7
exports[`client option configure client entry should disable client entry: response status 1`] = `200`;
8
8
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
+
9
15
exports[`client option default behaviour responds with a 200 status code for /ws path: console messages 1`] = `[]`;
10
16
11
17
exports[`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", () => {
193
193
} ) ;
194
194
} ) ;
195
195
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
+
196
256
describe ( "webSocketTransport" , ( ) => {
197
257
const clientModes = [
198
258
{
You can’t perform that action at this time.
0 commit comments