Skip to content

Commit fc88df5

Browse files
committed
test: update WebSocket handling in client tests to use CDP sessions
1 parent a181f84 commit fc88df5

File tree

1 file changed

+60
-9
lines changed

1 file changed

+60
-9
lines changed

test/e2e/client.test.js

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const webpack = require("webpack");
44
const Server = require("../../lib/Server");
55
const config = require("../fixtures/simple-config-other/webpack.config");
66
const runBrowser = require("../helpers/run-browser");
7+
const sessionSubscribe = require("../helpers/session-subscribe");
78
const port = require("../ports-map")["client-option"];
89

910
describe("client option", () => {
@@ -42,7 +43,7 @@ describe("client option", () => {
4243
await server.stop();
4344
});
4445

45-
it("responds with a 200 status code for /ws path", async () => {
46+
it("responds with a 200 status code for / path", async () => {
4647
page
4748
.on("console", (message) => {
4849
consoleMessages.push(message);
@@ -51,7 +52,22 @@ describe("client option", () => {
5152
pageErrors.push(error);
5253
});
5354

54-
const response = await page.goto(`http://localhost:${port}/ws`, {
55+
const webSocketRequests = [];
56+
const session = await page.target().createCDPSession();
57+
58+
session.on("Network.webSocketCreated", (test) => {
59+
webSocketRequests.push(test);
60+
});
61+
62+
await session.send("Target.setAutoAttach", {
63+
autoAttach: true,
64+
flatten: true,
65+
waitForDebuggerOnStart: true,
66+
});
67+
68+
sessionSubscribe(session);
69+
70+
const response = await page.goto(`http://localhost:${port}/`, {
5571
waitUntil: "networkidle0",
5672
});
5773

@@ -60,6 +76,8 @@ describe("client option", () => {
6076

6177
expect(response.status()).toMatchSnapshot("response status");
6278

79+
expect(webSocketRequests).toMatchSnapshot("webSockets");
80+
6381
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
6482
"console messages",
6583
);
@@ -119,14 +137,26 @@ describe("client option", () => {
119137
pageErrors.push(error);
120138
});
121139

122-
const response = await page.goto(
123-
`http://localhost:${port}/foo/test/bar`,
124-
{
125-
waitUntil: "networkidle0",
126-
},
127-
);
140+
const webSocketRequests = [];
141+
const session = await page.target().createCDPSession();
128142

129-
expect(response.status()).toMatchSnapshot("response status");
143+
session.on("Network.webSocketCreated", (test) => {
144+
webSocketRequests.push(test);
145+
});
146+
147+
await session.send("Target.setAutoAttach", {
148+
autoAttach: true,
149+
flatten: true,
150+
waitForDebuggerOnStart: true,
151+
});
152+
153+
sessionSubscribe(session);
154+
155+
await page.goto(`http://localhost:${port}/`, {
156+
waitUntil: "networkidle0",
157+
});
158+
159+
expect(webSocketRequests).toMatchSnapshot("webSockets");
130160

131161
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
132162
"console messages",
@@ -177,10 +207,31 @@ describe("client option", () => {
177207
pageErrors.push(error);
178208
});
179209

210+
const webSocketRequests = [];
211+
const session = await page.target().createCDPSession();
212+
213+
session.on("Network.webSocketCreated", (test) => {
214+
webSocketRequests.push(test);
215+
});
216+
217+
await session.send("Target.setAutoAttach", {
218+
autoAttach: true,
219+
flatten: true,
220+
waitForDebuggerOnStart: true,
221+
});
222+
223+
sessionSubscribe(session);
224+
225+
await page.goto(`http://localhost:${port}/`, {
226+
waitUntil: "networkidle0",
227+
});
228+
180229
const response = await page.goto(`http://localhost:${port}/main.js`, {
181230
waitUntil: "networkidle0",
182231
});
183232

233+
expect(webSocketRequests).toMatchSnapshot("webSockets");
234+
184235
expect(response.status()).toMatchSnapshot("response status");
185236

186237
expect(await response.text()).not.toMatch(/client\/index\.js/);

0 commit comments

Comments
 (0)