From 25776313347172291f8303ea5351f05c956bf500 Mon Sep 17 00:00:00 2001 From: dansu Date: Tue, 13 Jan 2015 10:38:53 +0100 Subject: [PATCH] Added unittests for websocket node --- test/nodes/core/io/22-websocket_spec.js | 223 ++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 test/nodes/core/io/22-websocket_spec.js diff --git a/test/nodes/core/io/22-websocket_spec.js b/test/nodes/core/io/22-websocket_spec.js new file mode 100644 index 000000000..4f1da5319 --- /dev/null +++ b/test/nodes/core/io/22-websocket_spec.js @@ -0,0 +1,223 @@ +/** + * Copyright 2014 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var ws = require("ws"); +var when = require("when"); +var should = require("should"); +var helper = require("../../helper.js"); +var websocketNode = require("../../../../nodes/core/io/22-websocket.js"); + +var sockets = []; +function createClient(listenerid) { + return when.promise(function(resolve, reject) { + var node = helper.getNode(listenerid); + var url = helper.url().replace(/http/, "ws") + node.path; + var sock = new ws(url); + sockets.push(sock); + + sock.on("open", function() { + resolve(sock); + }); + + sock.on("error", function(err) { + reject(err); + }); + }); +} + +function closeAll() { + for(var i=0;i