|
3 | 3 | const request = require("supertest");
|
4 | 4 | const path = require("path");
|
5 | 5 | const express = require("express");
|
| 6 | +const WebSocket = require("ws"); |
6 | 7 | const helper = require("./helper");
|
| 8 | +const should = require("should"); |
7 | 9 | const config = require("./fixtures/proxy-config/webpack.config");
|
8 | 10 |
|
| 11 | +const WebSocketServer = WebSocket.Server; |
9 | 12 | const contentBase = path.join(__dirname, "fixtures/proxy-config");
|
10 | 13 |
|
11 | 14 | const proxyOption = {
|
@@ -184,4 +187,48 @@ describe("Proxy", function() {
|
184 | 187 | req.get("/proxy2").expect(200, "from proxy", done);
|
185 | 188 | });
|
186 | 189 | });
|
| 190 | + |
| 191 | + context("External websocket upgrade", function() { |
| 192 | + let ws; |
| 193 | + let wsServer; |
| 194 | + let responseMessage; |
| 195 | + |
| 196 | + before(function(done) { |
| 197 | + helper.start(config, { |
| 198 | + contentBase, |
| 199 | + proxy: [{ |
| 200 | + context: "/", |
| 201 | + target: "http://localhost:9003", |
| 202 | + ws: true |
| 203 | + }] |
| 204 | + }, done); |
| 205 | + |
| 206 | + wsServer = new WebSocketServer({ port: 9003 }); |
| 207 | + wsServer.on("connection", function connection(ws) { |
| 208 | + ws.on("message", function incoming(message) { |
| 209 | + ws.send(message); |
| 210 | + }); |
| 211 | + }); |
| 212 | + }); |
| 213 | + |
| 214 | + beforeEach(function(done) { |
| 215 | + ws = new WebSocket("ws://localhost:8080/proxy3/socket"); |
| 216 | + ws.on("message", function(message) { |
| 217 | + responseMessage = message; |
| 218 | + done() |
| 219 | + }); |
| 220 | + ws.on("open", function open() { |
| 221 | + ws.send("foo"); |
| 222 | + }); |
| 223 | + }) |
| 224 | + |
| 225 | + it("Should receive response", function() { |
| 226 | + should(responseMessage).equal("foo"); |
| 227 | + }); |
| 228 | + |
| 229 | + after(function(done) { |
| 230 | + wsServer.close(); |
| 231 | + helper.close(done); |
| 232 | + }); |
| 233 | + }); |
187 | 234 | });
|
0 commit comments