javascript - Creating a WebSocket Client for Mocha tests within a Sails.js app? -


i'm trying use socket.io-client in mocha tests of sails js app calls below. .get/.post not invoked , test case times out.

var io = require('socket.io-client'); io.sails.url = sails.getbaseurl();  // doesn't work io.socket.get('/hello', function serverresponded (body, jwr) {   console.log('sails responded with: ', body);   console.log('with headers: ', jwr.headers);   console.log('and status code: ', jwr.statuscode);   io.socket.disconnect();  }); 

it looks you're confusing socket.io-client, low-level socket.io client library, sails.io.js, sails.js utility communicating sails app on sockets. take @ sails.io.js readme instructions on how use sails socket client node:

var socketioclient = require('socket.io-client'); var sailsioclient = require('sails.io.js');  // instantiate socket client (`io`) // (for now, must explicitly pass in socket.io client when using library node.js) var io = sailsioclient(socketioclient);  // set options: // (you have specify host , port of sails backend when using library node.js) io.sails.url = 'http://localhost:1337'; // ...  // send request `http://localhost:1337/hello`: io.socket.get('/hello', function serverresponded (body, jwr) {   // body === jwr.body   console.log('sails responded with: ', body);   console.log('with headers: ', jwr.headers);   console.log('and status code: ', jwr.statuscode);    // ...   // more stuff   // ...     // when finished `io.socket`, or other sockets connect manually,   // should make sure , disconnect them, e.g.:   io.socket.disconnect();    // (note there no callback argument `.disconnect` method) }); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -