diff --git a/test/e2e/__snapshots__/web-socket-server-url.test.js.snap.webpack4 b/test/e2e/__snapshots__/web-socket-server-url.test.js.snap.webpack4 index 6346752917..ef0a271f83 100644 --- a/test/e2e/__snapshots__/web-socket-server-url.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/web-socket-server-url.test.js.snap.webpack4 @@ -303,6 +303,50 @@ Array [ exports[`web socket server URL should work with "https" option ("ws"): page errors 1`] = `Array []`; +exports[`web socket server URL should work with "server: 'https'" option ("sockjs"): console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`web socket server URL should work with "server: 'https'" option ("sockjs"): page errors 1`] = `Array []`; + +exports[`web socket server URL should work with "server: 'https'" option ("ws"): console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`web socket server URL should work with "server: 'https'" option ("ws"): page errors 1`] = `Array []`; + +exports[`web socket server URL should work with "server: 'spdy'" option ("sockjs"): console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`web socket server URL should work with "server: 'spdy'" option ("sockjs"): page errors 1`] = `Array []`; + +exports[`web socket server URL should work with "server: 'spdy'" option ("ws"): console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`web socket server URL should work with "server: 'spdy'" option ("ws"): page errors 1`] = `Array []`; + exports[`web socket server URL should work with default "/ws" value of the "client.webSocketURL.pathname" option ("sockjs"): console messages 1`] = ` Array [ "[HMR] Waiting for update signal from WDS...", diff --git a/test/e2e/__snapshots__/web-socket-server-url.test.js.snap.webpack5 b/test/e2e/__snapshots__/web-socket-server-url.test.js.snap.webpack5 index 6346752917..ef0a271f83 100644 --- a/test/e2e/__snapshots__/web-socket-server-url.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/web-socket-server-url.test.js.snap.webpack5 @@ -303,6 +303,50 @@ Array [ exports[`web socket server URL should work with "https" option ("ws"): page errors 1`] = `Array []`; +exports[`web socket server URL should work with "server: 'https'" option ("sockjs"): console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`web socket server URL should work with "server: 'https'" option ("sockjs"): page errors 1`] = `Array []`; + +exports[`web socket server URL should work with "server: 'https'" option ("ws"): console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`web socket server URL should work with "server: 'https'" option ("ws"): page errors 1`] = `Array []`; + +exports[`web socket server URL should work with "server: 'spdy'" option ("sockjs"): console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`web socket server URL should work with "server: 'spdy'" option ("sockjs"): page errors 1`] = `Array []`; + +exports[`web socket server URL should work with "server: 'spdy'" option ("ws"): console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`web socket server URL should work with "server: 'spdy'" option ("ws"): page errors 1`] = `Array []`; + exports[`web socket server URL should work with default "/ws" value of the "client.webSocketURL.pathname" option ("sockjs"): console messages 1`] = ` Array [ "[HMR] Waiting for update signal from WDS...", diff --git a/test/e2e/web-socket-server-url.test.js b/test/e2e/web-socket-server-url.test.js index 6a5200505a..a83f3d3890 100644 --- a/test/e2e/web-socket-server-url.test.js +++ b/test/e2e/web-socket-server-url.test.js @@ -2066,6 +2066,134 @@ describe("web socket server URL", () => { await server.stop(); }); + it(`should work with "server: 'https'" option ("${webSocketServer}")`, async () => { + const hostname = "127.0.0.1"; + const compiler = webpack(config); + const devServerOptions = { + webSocketServer, + port: port1, + server: "https", + }; + const server = new Server(devServerOptions, compiler); + + await server.start(); + + const { page, browser } = await runBrowser(); + + const pageErrors = []; + const consoleMessages = []; + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const webSocketRequests = []; + + if (webSocketServer === "ws") { + const client = page._client; + + client.on("Network.webSocketCreated", (test) => { + webSocketRequests.push(test); + }); + } else { + page.on("request", (request) => { + if (/\/ws\//.test(request.url())) { + webSocketRequests.push({ url: request.url() }); + } + }); + } + + await page.goto(`https://${hostname}:${port1}/`, { + waitUntil: "networkidle0", + }); + + const webSocketRequest = webSocketRequests[0]; + + if (webSocketServer === "ws") { + expect(webSocketRequest.url).toContain(`wss://${hostname}:${port1}/ws`); + } else { + expect(webSocketRequest.url).toContain( + `https://${hostname}:${port1}/ws` + ); + } + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + expect(pageErrors).toMatchSnapshot("page errors"); + + await browser.close(); + await server.stop(); + }); + + it(`should work with "server: 'spdy'" option ("${webSocketServer}")`, async () => { + const hostname = "127.0.0.1"; + const compiler = webpack(config); + const devServerOptions = { + webSocketServer, + port: port1, + server: "spdy", + }; + const server = new Server(devServerOptions, compiler); + + await server.start(); + + const { page, browser } = await runBrowser(); + + const pageErrors = []; + const consoleMessages = []; + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const webSocketRequests = []; + + if (webSocketServer === "ws") { + const client = page._client; + + client.on("Network.webSocketCreated", (test) => { + webSocketRequests.push(test); + }); + } else { + page.on("request", (request) => { + if (/\/ws\//.test(request.url())) { + webSocketRequests.push({ url: request.url() }); + } + }); + } + + await page.goto(`https://${hostname}:${port1}/`, { + waitUntil: "networkidle0", + }); + + const webSocketRequest = webSocketRequests[0]; + + if (webSocketServer === "ws") { + expect(webSocketRequest.url).toContain(`wss://${hostname}:${port1}/ws`); + } else { + expect(webSocketRequest.url).toContain( + `https://${hostname}:${port1}/ws` + ); + } + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + expect(pageErrors).toMatchSnapshot("page errors"); + + await browser.close(); + await server.stop(); + }); + it(`should work when "port" option is "auto" ("${webSocketServer}")`, async () => { process.env.WEBPACK_DEV_SERVER_BASE_PORT = 50000;