2017-03-28 7 views
0

私のSails JSアプリのMochaテストでsocket.io-clientを使って、以下のような呼び出しをしようとしています。しかし.get/.postは呼び出されず、テストケースはタイムアウトします。Sails.jsアプリケーション内でMochaテスト用のWebSocketクライアントを作成しますか?

var io = require('socket.io-client'); 
io.sails.url = sails.getBaseUrl(); 

// This 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 with status code: ', JWR.statusCode); 
    io.socket.disconnect(); 

}); 

答えて

0

あなたがsocket.io-clientを混乱しているようですが、ソケットの上に帆アプリと通信するためのSails.jsユーティリティである、sails.io.jsで、低レベルSocket.ioクライアントライブラリである、見えます。ノードからSailsソケットクライアントを使用する方法については、sails.io.js READMEをご覧ください。

var socketIOClient = require('socket.io-client'); 
var sailsIOClient = require('sails.io.js'); 

// Instantiate the socket client (`io`) 
// (for now, you must explicitly pass in the socket.io client when using this library from Node.js) 
var io = sailsIOClient(socketIOClient); 

// Set some options: 
// (you have to specify the host and port of the Sails backend when using this library from Node.js) 
io.sails.url = 'http://localhost:1337'; 
// ... 

// Send a GET request to `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 with status code: ', JWR.statusCode); 

    // ... 
    // more stuff 
    // ... 


    // When you are finished with `io.socket`, or any other sockets you connect manually, 
    // you should make sure and disconnect them, e.g.: 
    io.socket.disconnect(); 

    // (note that there is no callback argument to the `.disconnect` method) 
}); 
関連する問題