-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid web socket connection when web socket server is not running (
- Loading branch information
1 parent
094c932
commit 8874d72
Showing
8 changed files
with
105 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/e2e/__snapshots__/web-socket-server.test.js.snap.webpack4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`web socket server should work allow to disable: console messages 1`] = ` | ||
Array [ | ||
"Hey.", | ||
] | ||
`; | ||
|
||
exports[`web socket server should work allow to disable: page errors 1`] = `Array []`; |
9 changes: 9 additions & 0 deletions
9
test/e2e/__snapshots__/web-socket-server.test.js.snap.webpack5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`web socket server should work allow to disable: console messages 1`] = ` | ||
Array [ | ||
"Hey.", | ||
] | ||
`; | ||
|
||
exports[`web socket server should work allow to disable: page errors 1`] = `Array []`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use strict"; | ||
|
||
const webpack = require("webpack"); | ||
const Server = require("../../lib/Server"); | ||
const config = require("../fixtures/client-config/webpack.config"); | ||
const runBrowser = require("../helpers/run-browser"); | ||
const port = require("../ports-map")["web-socket-server-test"]; | ||
|
||
describe("web socket server", () => { | ||
it("should work allow to disable", async () => { | ||
const devServerPort = port; | ||
|
||
const compiler = webpack(config); | ||
const devServerOptions = { | ||
webSocketServer: false, | ||
port: devServerPort, | ||
}; | ||
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 = []; | ||
|
||
const client = page._client; | ||
|
||
client.on("Network.webSocketCreated", (test) => { | ||
webSocketRequests.push(test); | ||
}); | ||
|
||
await page.goto(`http://127.0.0.1:${port}/main`, { | ||
waitUntil: "networkidle0", | ||
}); | ||
|
||
expect(webSocketRequests).toHaveLength(0); | ||
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( | ||
"console messages" | ||
); | ||
expect(pageErrors).toMatchSnapshot("page errors"); | ||
|
||
await browser.close(); | ||
await server.stop(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters