|
2 | 2 |
|
3 | 3 | const webpack = require("webpack");
|
4 | 4 | const WebSocket = require("ws");
|
5 |
| -const { describe, test, beforeAll } = require("@playwright/test"); |
| 5 | +const { describe, test } = require("@playwright/test"); |
6 | 6 | const Server = require("../../lib/Server");
|
7 | 7 | const { expect } = require("../helpers/playwright-custom-expects");
|
8 | 8 | const WebsocketServer = require("../../lib/servers/WebsocketServer");
|
9 | 9 | const config = require("../fixtures/client-config/webpack.config");
|
10 | 10 | const port = require("../ports-map")["web-socket-communication"];
|
11 | 11 |
|
12 |
| -describe("web socket communication", () => { |
13 |
| - beforeAll(async () => { |
14 |
| - test.setTimeout(60_000); |
15 |
| - }) |
| 12 | +test.setTimeout(60_000); |
16 | 13 |
|
| 14 | +describe("web socket communication", () => { |
17 | 15 | const webSocketServers = ["ws", "sockjs"];
|
18 | 16 | webSocketServers.forEach((websocketServer) => {
|
19 | 17 | test(`should work and close web socket client connection when web socket server closed ("${websocketServer}")`, async ({
|
@@ -67,54 +65,55 @@ describe("web socket communication", () => {
|
67 | 65 | });
|
68 | 66 |
|
69 | 67 | // 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); |
74 | 79 |
|
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(); |
81 | 81 |
|
82 |
| - await server.start(); |
| 82 | + try { |
| 83 | + const pageErrors = []; |
| 84 | + const consoleMessages = []; |
83 | 85 |
|
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 | + }); |
87 | 93 |
|
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", |
94 | 96 | });
|
95 | 97 |
|
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 | + }); |
106 | 104 |
|
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 | + ); |
118 | 117 |
|
119 | 118 | test(`should work and reconnect when the connection is lost ("${websocketServer}")`, async ({
|
120 | 119 | page,
|
@@ -154,7 +153,7 @@ describe("web socket communication", () => {
|
154 | 153 | });
|
155 | 154 |
|
156 | 155 | expect(
|
157 |
| - consoleMessages.map((message) => message.text()) |
| 156 | + consoleMessages.map((message) => message.text()), |
158 | 157 | ).toMatchSnapshotWithArray();
|
159 | 158 | expect(pageErrors).toMatchSnapshotWithArray();
|
160 | 159 | } catch (error) {
|
|
0 commit comments