Skip to content

Commit 41ce65c

Browse files
snitin315alexander-akait
authored andcommitted
test: refactor web socket server tests to cleanup properly (#4921)
1 parent 1cfd6ca commit 41ce65c

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

test/e2e/web-socket-server.test.js

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,40 @@ describe("web socket server", () => {
2121

2222
const { page, browser } = await runBrowser();
2323

24-
const pageErrors = [];
25-
const consoleMessages = [];
26-
27-
page
28-
.on("console", (message) => {
29-
consoleMessages.push(message);
30-
})
31-
.on("pageerror", (error) => {
32-
pageErrors.push(error);
33-
});
24+
try {
25+
const pageErrors = [];
26+
const consoleMessages = [];
3427

35-
const webSocketRequests = [];
28+
page
29+
.on("console", (message) => {
30+
consoleMessages.push(message);
31+
})
32+
.on("pageerror", (error) => {
33+
pageErrors.push(error);
34+
});
3635

37-
const client = page._client;
36+
const webSocketRequests = [];
3837

39-
client.on("Network.webSocketCreated", (test) => {
40-
webSocketRequests.push(test);
41-
});
38+
const client = page._client;
4239

43-
await page.goto(`http://127.0.0.1:${port}/`, {
44-
waitUntil: "networkidle0",
45-
});
40+
client.on("Network.webSocketCreated", (test) => {
41+
webSocketRequests.push(test);
42+
});
4643

47-
expect(webSocketRequests).toHaveLength(0);
48-
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
49-
"console messages"
50-
);
51-
expect(pageErrors).toMatchSnapshot("page errors");
44+
await page.goto(`http://127.0.0.1:${port}/`, {
45+
waitUntil: "networkidle0",
46+
});
5247

53-
await browser.close();
54-
await server.stop();
48+
expect(webSocketRequests).toHaveLength(0);
49+
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
50+
"console messages"
51+
);
52+
expect(pageErrors).toMatchSnapshot("page errors");
53+
} catch (error) {
54+
throw error;
55+
} finally {
56+
await browser.close();
57+
await server.stop();
58+
}
5559
});
5660
});

0 commit comments

Comments
 (0)