Skip to content

Commit 54976c9

Browse files
authored
chore: remove SockJS support and related tests from the project
1 parent 3f8443c commit 54976c9

File tree

4 files changed

+32
-261
lines changed

4 files changed

+32
-261
lines changed

lib/Server.js

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,56 +2042,6 @@ class Server {
20422042
middleware: /** @type {MiddlewareHandler} */ (this.middleware),
20432043
});
20442044

2045-
// Should be after `webpack-dev-middleware`, otherwise other middlewares might rewrite response
2046-
middlewares.push({
2047-
name: "webpack-dev-server-sockjs-bundle",
2048-
path: "/__webpack_dev_server__/sockjs.bundle.js",
2049-
/**
2050-
* @param {Request} req request
2051-
* @param {Response} res response
2052-
* @param {NextFunction} next next function
2053-
* @returns {void}
2054-
*/
2055-
middleware: (req, res, next) => {
2056-
if (req.method !== "GET" && req.method !== "HEAD") {
2057-
next();
2058-
return;
2059-
}
2060-
2061-
const clientPath = path.join(
2062-
__dirname,
2063-
"..",
2064-
"client/modules/sockjs-client/index.js",
2065-
);
2066-
2067-
// Express send Etag and other headers by default, so let's keep them for compatibility reasons
2068-
if (typeof res.sendFile === "function") {
2069-
res.sendFile(clientPath);
2070-
return;
2071-
}
2072-
2073-
let stats;
2074-
2075-
try {
2076-
// TODO implement `inputFileSystem.createReadStream` in webpack
2077-
stats = fs.statSync(clientPath);
2078-
} catch {
2079-
next();
2080-
return;
2081-
}
2082-
2083-
res.setHeader("Content-Type", "application/javascript; charset=UTF-8");
2084-
res.setHeader("Content-Length", stats.size);
2085-
2086-
if (req.method === "HEAD") {
2087-
res.end();
2088-
return;
2089-
}
2090-
2091-
fs.createReadStream(clientPath).pipe(res);
2092-
},
2093-
});
2094-
20952045
middlewares.push({
20962046
name: "webpack-dev-server-invalidate",
20972047
path: "/webpack-dev-server/invalidate",
@@ -3288,8 +3238,7 @@ class Server {
32883238
*/
32893239
sendMessage(clients, type, data, params) {
32903240
for (const client of clients) {
3291-
// `sockjs` uses `1` to indicate client is ready to accept data
3292-
// `ws` uses `WebSocket.OPEN`, but it is mean `1` too
3241+
// `ws` uses `WebSocket.OPEN`, which is `1`
32933242
if (client.readyState === 1) {
32943243
client.send(JSON.stringify({ type, data, params }));
32953244
}

test/e2e/built-in-routes.test.js

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -33,69 +33,6 @@ describe("Built in routes", () => {
3333
await server.stop();
3434
});
3535

36-
it("should handles GET request to sockjs bundle", async () => {
37-
page
38-
.on("console", (message) => {
39-
consoleMessages.push(message);
40-
})
41-
.on("pageerror", (error) => {
42-
pageErrors.push(error);
43-
});
44-
45-
const response = await page.goto(
46-
`http://localhost:${port}/__webpack_dev_server__/sockjs.bundle.js`,
47-
{
48-
waitUntil: "networkidle0",
49-
},
50-
);
51-
52-
expect(response.headers()["content-type"]).toMatchSnapshot(
53-
"response headers content-type",
54-
);
55-
56-
expect(response.status()).toMatchSnapshot("response status");
57-
58-
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
59-
"console messages",
60-
);
61-
62-
expect(pageErrors).toMatchSnapshot("page errors");
63-
});
64-
65-
it("should handles HEAD request to sockjs bundle", async () => {
66-
page
67-
.on("console", (message) => {
68-
consoleMessages.push(message);
69-
})
70-
.on("pageerror", (error) => {
71-
pageErrors.push(error);
72-
})
73-
.on("request", (interceptedRequest) => {
74-
if (interceptedRequest.isInterceptResolutionHandled()) return;
75-
76-
interceptedRequest.continue({ method: "HEAD" }, 10);
77-
});
78-
79-
const response = await page.goto(
80-
`http://localhost:${port}/__webpack_dev_server__/sockjs.bundle.js`,
81-
{
82-
waitUntil: "networkidle0",
83-
},
84-
);
85-
86-
expect(response.headers()["content-type"]).toMatchSnapshot(
87-
"response headers content-type",
88-
);
89-
90-
expect(response.status()).toMatchSnapshot("response status");
91-
92-
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
93-
"console messages",
94-
);
95-
96-
expect(pageErrors).toMatchSnapshot("page errors");
97-
});
98-
9936
it("should handle GET request to invalidate endpoint", async () => {
10037
page
10138
.on("console", (message) => {

test/e2e/hot-and-live-reload.test.js

Lines changed: 30 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
const path = require("node:path");
88
const fs = require("graceful-fs");
9-
const SockJS = require("sockjs-client");
109
const webpack = require("webpack");
1110
const WebSocket = require("ws");
1211
const Server = require("../../lib/Server");
@@ -25,7 +24,6 @@ const cssFilePath = path.resolve(
2524
const INVALID_MESSAGE = "[webpack-dev-server] App updated. Recompiling...";
2625

2726
describe("hot and live reload", () => {
28-
// "sockjs" client cannot add additional headers
2927
const modes = [
3028
{
3129
title: "should work and refresh content using hot module replacement",
@@ -133,70 +131,6 @@ describe("hot and live reload", () => {
133131
hot: true,
134132
},
135133
},
136-
// "sockjs" web socket serve
137-
{
138-
title:
139-
"should work and refresh content using hot module replacement when hot enabled",
140-
options: {
141-
allowedHosts: "all",
142-
143-
webSocketServer: "sockjs",
144-
hot: true,
145-
},
146-
},
147-
{
148-
title:
149-
"should work and refresh content using hot module replacement when live reload enabled",
150-
options: {
151-
allowedHosts: "all",
152-
153-
webSocketServer: "sockjs",
154-
liveReload: true,
155-
},
156-
},
157-
{
158-
title: "should not refresh content when hot and no live reload disabled",
159-
options: {
160-
allowedHosts: "all",
161-
162-
webSocketServer: "sockjs",
163-
hot: false,
164-
liveReload: false,
165-
},
166-
},
167-
{
168-
title:
169-
"should work and refresh content using hot module replacement when live reload disabled and hot enabled",
170-
options: {
171-
allowedHosts: "all",
172-
173-
webSocketServer: "sockjs",
174-
liveReload: false,
175-
hot: true,
176-
},
177-
},
178-
{
179-
title:
180-
"should work and refresh content using live reload when live reload disabled and hot enabled",
181-
options: {
182-
allowedHosts: "all",
183-
184-
webSocketServer: "sockjs",
185-
liveReload: true,
186-
hot: false,
187-
},
188-
},
189-
{
190-
title:
191-
"should work and refresh content using hot module replacement when live reload and hot enabled",
192-
options: {
193-
allowedHosts: "all",
194-
195-
webSocketServer: "sockjs",
196-
liveReload: true,
197-
hot: true,
198-
},
199-
},
200134
{
201135
title:
202136
'should work and allow to disable hot module replacement using the "webpack-dev-server-hot=false"',
@@ -347,89 +281,44 @@ describe("hot and live reload", () => {
347281
testDevServerOptions.webSocketServer !== false;
348282

349283
await new Promise((resolve) => {
350-
const webSocketTransport =
351-
typeof testDevServerOptions.webSocketServer !== "undefined" &&
352-
testDevServerOptions.webSocketServer !== false
353-
? testDevServerOptions.webSocketServer
354-
: "ws";
355-
356-
if (webSocketTransport === "ws") {
357-
const ws = new WebSocket(
358-
`ws://localhost:${devServerOptions.port}/ws`,
359-
{
360-
headers: {
361-
host: `localhost:${devServerOptions.port}`,
362-
origin: `http://localhost:${devServerOptions.port}`,
363-
},
364-
},
365-
);
366-
367-
let opened = false;
368-
let received = false;
369-
let errored = false;
370-
371-
ws.on("error", (_error) => {
372-
errored = true;
373-
374-
ws.close();
375-
});
376-
377-
ws.on("open", () => {
378-
opened = true;
379-
});
380-
381-
ws.on("message", (data) => {
382-
const message = JSON.parse(data);
383-
384-
if (message.type === "ok") {
385-
received = true;
284+
const ws = new WebSocket(`ws://localhost:${devServerOptions.port}/ws`, {
285+
headers: {
286+
host: `localhost:${devServerOptions.port}`,
287+
origin: `http://localhost:${devServerOptions.port}`,
288+
},
289+
});
386290

387-
ws.close();
388-
}
389-
});
291+
let opened = false;
292+
let received = false;
293+
let errored = false;
390294

391-
ws.on("close", () => {
392-
if (opened && received && !errored) {
393-
resolve();
394-
} else if (!webSocketServerLaunched && errored) {
395-
resolve();
396-
}
397-
});
398-
} else {
399-
const sockjs = new SockJS(
400-
`http://localhost:${devServerOptions.port}/ws`,
401-
);
295+
ws.on("error", (_error) => {
296+
errored = true;
402297

403-
let opened = false;
404-
let received = false;
405-
let errored = false;
406-
407-
sockjs.onerror = () => {
408-
errored = true;
409-
};
298+
ws.close();
299+
});
410300

411-
sockjs.onopen = () => {
412-
opened = true;
413-
};
301+
ws.on("open", () => {
302+
opened = true;
303+
});
414304

415-
sockjs.onmessage = ({ data }) => {
416-
const message = JSON.parse(data);
305+
ws.on("message", (data) => {
306+
const message = JSON.parse(data);
417307

418-
if (message.type === "ok") {
419-
received = true;
308+
if (message.type === "ok") {
309+
received = true;
420310

421-
sockjs.close();
422-
}
423-
};
311+
ws.close();
312+
}
313+
});
424314

425-
sockjs.onclose = (event) => {
426-
if (opened && received && !errored) {
427-
resolve();
428-
} else if (event && event.reason === "Cannot connect to server") {
429-
resolve();
430-
}
431-
};
432-
}
315+
ws.on("close", () => {
316+
if (opened && received && !errored) {
317+
resolve();
318+
} else if (!webSocketServerLaunched && errored) {
319+
resolve();
320+
}
321+
});
433322
});
434323

435324
const launched = await runBrowser();

test/validate-options.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ const tests = {
6868
},
6969
},
7070
{
71-
webSocketTransport: "sockjs",
72-
},
73-
{
74-
webSocketTransport: require.resolve("../client/clients/SockJSClient"),
71+
webSocketTransport: "ws",
7572
},
7673
{
7774
webSocketURL: "ws://localhost:8080",
@@ -502,7 +499,6 @@ const tests = {
502499
success: [
503500
false,
504501
"ws",
505-
"sockjs",
506502
{
507503
type: "ws",
508504
options: {

0 commit comments

Comments
 (0)