From 68e51bb886eb1724c789eaf3bded850111635fab Mon Sep 17 00:00:00 2001 From: dansu Date: Sat, 17 Jan 2015 10:51:10 +0100 Subject: [PATCH] added tests for websocket-client cleanup and prettify --- test/nodes/core/io/22-websocket_spec.js | 451 +++++++++++++++++------- 1 file changed, 319 insertions(+), 132 deletions(-) diff --git a/test/nodes/core/io/22-websocket_spec.js b/test/nodes/core/io/22-websocket_spec.js index 4f1da5319..d6643a7a6 100644 --- a/test/nodes/core/io/22-websocket_spec.js +++ b/test/nodes/core/io/22-websocket_spec.js @@ -21,10 +21,15 @@ var helper = require("../../helper.js"); var websocketNode = require("../../../../nodes/core/io/22-websocket.js"); var sockets = []; + +function getWsUrl(path) { + return helper.url().replace(/http/, "ws") + path; +} + function createClient(listenerid) { return when.promise(function(resolve, reject) { var node = helper.getNode(listenerid); - var url = helper.url().replace(/http/, "ws") + node.path; + var url = getWsUrl(node.path); var sock = new ws(url); sockets.push(sock); @@ -39,184 +44,366 @@ function createClient(listenerid) { } function closeAll() { - for(var i=0;i 20) { + helper.clearFlows(); + done(); + } }); - sock.send('{"text":"hello"}'); - }); - }); - }); - - it('should broadcast', function(done) { - var flow = [{id:"n1", type:"websocket-listener", path: "/ws" }, - {id:"n2", server:"n1", type:"websocket out" }, - {id:"n3", type: "helper", wires: [["n2"]]} - ]; - helper.load(websocketNode, flow, function() { - var def1 = when.defer(), def2 = when.defer(); - when.all([createClient("n1"), createClient("n1")]).then(function(socks){ - socks[0].on("message", function(msg, flags) { - msg.should.equal("hello"); - def1.resolve(); - }); - socks[1].on("message", function(msg, flags) { - msg.should.equal("hello"); - def2.resolve(); - }); - var n3 = helper.getNode("n3"); - n3.send({payload:"hello"}); - }); - - when.all([def1.promise, def2.promise]).then(function(){ - done(); }); }); });