Skip to content

Commit 6ae0b39

Browse files
committed
test: move web-socker-server.test.js to Playwright
1 parent 9b11e01 commit 6ae0b39

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"use strict";
2+
3+
const webpack = require("webpack");
4+
const { test } = require("@playwright/test");
5+
const { describe } = require("@playwright/test");
6+
const { expect } = require("@playwright/test");
7+
const Server = require("../../lib/Server");
8+
const config = require("../fixtures/client-config/webpack.config");
9+
const sessionSubscribe = require("../helpers/session-subscribe");
10+
const port = require("../ports-map")["web-socket-server-test"];
11+
12+
describe("web socket server", () => {
13+
test("should work allow to disable", async ({ page }) => {
14+
const devServerPort = port;
15+
16+
const compiler = webpack(config);
17+
const devServerOptions = {
18+
webSocketServer: false,
19+
port: devServerPort,
20+
};
21+
const server = new Server(devServerOptions, compiler);
22+
23+
await server.start();
24+
25+
try {
26+
const pageErrors = [];
27+
const consoleMessages = [];
28+
29+
page
30+
.on("console", (message) => {
31+
consoleMessages.push(message);
32+
})
33+
.on("pageerror", (error) => {
34+
pageErrors.push(error);
35+
});
36+
37+
const webSocketRequests = [];
38+
const session = await page.context().newCDPSession(page);
39+
40+
session.on("Network.webSocketCreated", (payload) => {
41+
webSocketRequests.push(payload);
42+
});
43+
44+
await session.send("Target.setAutoAttach", {
45+
autoAttach: true,
46+
flatten: true,
47+
waitForDebuggerOnStart: true,
48+
});
49+
50+
sessionSubscribe(session);
51+
52+
await page.goto(`http://127.0.0.1:${port}/`, {
53+
waitUntil: "networkidle0",
54+
});
55+
56+
expect(webSocketRequests).toHaveLength(0);
57+
expect(
58+
JSON.stringify(consoleMessages.map((message) => message.text())),
59+
).toMatchSnapshot();
60+
expect(JSON.stringify(pageErrors)).toMatchSnapshot();
61+
} catch (error) {
62+
throw error;
63+
} finally {
64+
await server.stop();
65+
}
66+
});
67+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["Hey."]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)