Skip to content

Commit 76a469e

Browse files
committed
feat: remove redundant beforeAll in web-socket-communication.test.js
1 parent bf11adb commit 76a469e

File tree

1 file changed

+46
-47
lines changed

1 file changed

+46
-47
lines changed

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

+46-47
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
const webpack = require("webpack");
44
const WebSocket = require("ws");
5-
const { describe, test, beforeAll } = require("@playwright/test");
5+
const { describe, test } = require("@playwright/test");
66
const Server = require("../../lib/Server");
77
const { expect } = require("../helpers/playwright-custom-expects");
88
const WebsocketServer = require("../../lib/servers/WebsocketServer");
99
const config = require("../fixtures/client-config/webpack.config");
1010
const port = require("../ports-map")["web-socket-communication"];
1111

12-
describe("web socket communication", () => {
13-
beforeAll(async () => {
14-
test.setTimeout(60_000);
15-
})
12+
test.setTimeout(60_000);
1613

14+
describe("web socket communication", () => {
1715
const webSocketServers = ["ws", "sockjs"];
1816
webSocketServers.forEach((websocketServer) => {
1917
test(`should work and close web socket client connection when web socket server closed ("${websocketServer}")`, async ({
@@ -67,54 +65,55 @@ describe("web socket communication", () => {
6765
});
6866

6967
// TODO: test fails, is there sth wrong with the timeout?
70-
test.fixme(`should work and terminate client that is not alive ("${websocketServer}")`, async ({
71-
page,
72-
}) => {
73-
WebsocketServer.heartbeatInterval = 100;
68+
test.fixme(
69+
`should work and terminate client that is not alive ("${websocketServer}")`,
70+
async ({ page }) => {
71+
WebsocketServer.heartbeatInterval = 100;
72+
73+
const compiler = webpack(config);
74+
const devServerOptions = {
75+
port,
76+
webSocketServer: websocketServer,
77+
};
78+
const server = new Server(devServerOptions, compiler);
7479

75-
const compiler = webpack(config);
76-
const devServerOptions = {
77-
port,
78-
webSocketServer: websocketServer,
79-
};
80-
const server = new Server(devServerOptions, compiler);
80+
await server.start();
8181

82-
await server.start();
82+
try {
83+
const pageErrors = [];
84+
const consoleMessages = [];
8385

84-
try {
85-
const pageErrors = [];
86-
const consoleMessages = [];
86+
page
87+
.on("console", (message) => {
88+
consoleMessages.push(message);
89+
})
90+
.on("pageerror", (error) => {
91+
pageErrors.push(error);
92+
});
8793

88-
page
89-
.on("console", (message) => {
90-
consoleMessages.push(message);
91-
})
92-
.on("pageerror", (error) => {
93-
pageErrors.push(error);
94+
await page.goto(`http://127.0.0.1:${port}/`, {
95+
waitUntil: "networkidle0",
9496
});
9597

96-
await page.goto(`http://127.0.0.1:${port}/`, {
97-
waitUntil: "networkidle0",
98-
});
99-
100-
// Wait heartbeat
101-
await new Promise((resolve) => {
102-
setTimeout(() => {
103-
resolve();
104-
}, 200);
105-
});
98+
// Wait heartbeat
99+
await new Promise((resolve) => {
100+
setTimeout(() => {
101+
resolve();
102+
}, 200);
103+
});
106104

107-
expect(server.webSocketServer.clients.length).toBe(0);
108-
expect(
109-
consoleMessages.map((message) => message.text())
110-
).toMatchSnapshotWithArray();
111-
expect(pageErrors).toMatchSnapshotWithArray();
112-
} catch (error) {
113-
throw error;
114-
} finally {
115-
await server.stop();
116-
}
117-
});
105+
expect(server.webSocketServer.clients.length).toBe(0);
106+
expect(
107+
consoleMessages.map((message) => message.text()),
108+
).toMatchSnapshotWithArray();
109+
expect(pageErrors).toMatchSnapshotWithArray();
110+
} catch (error) {
111+
throw error;
112+
} finally {
113+
await server.stop();
114+
}
115+
},
116+
);
118117

119118
test(`should work and reconnect when the connection is lost ("${websocketServer}")`, async ({
120119
page,
@@ -154,7 +153,7 @@ describe("web socket communication", () => {
154153
});
155154

156155
expect(
157-
consoleMessages.map((message) => message.text())
156+
consoleMessages.map((message) => message.text()),
158157
).toMatchSnapshotWithArray();
159158
expect(pageErrors).toMatchSnapshotWithArray();
160159
} catch (error) {

0 commit comments

Comments
 (0)