使用mocha的单元测试socket.io

o3imoua4  于 2021-06-10  发布在  Redis
关注(0)|答案(0)|浏览(223)

你能帮我用mocha为这段代码编写单元测试用例吗。无法找到适合此代码的更好解决方案。我试过一些解决办法,但不管用
谢谢

const server = require('http').Server(app);
const redis = require('redis');

var client = redis.createClient(process.env.redisPort,process.env.redisHost);
var client1 = redis.createClient(process.env.redisPort,process.env.redisHost);
var client2 = redis.createClient(process.env.redisPort,process.env.redisHost);
var client3 = redis.createClient(process.env.redisPort,process.env.redisHost);
const io = require('socket.io')(server, {path: '/ws'});;
const port = parseInt(process.env.PORT, 10) || 35082;
server.listen(port);

app.get('/', function (req, res) {
  res.send('ws server');
});

io.sockets
  .on('connection', 
  (socket) => {
    console.log("Socket Connected");
    client.on('message',function(channel,msg){
      socket.emit('pickedup',msg);
    });
    client.subscribe('pickedup');

    client1.on('message',function(channel,msg){
      socket.emit('order-da-issue',msg);
    });
    client1.subscribe('da-issue');

    client2.on('message',function(channel,msg){
      socket.emit('crew-issue',msg);
    });
    client2.subscribe('crew-issue');

    client3.on('message',function(channel,msg){
      socket.emit('da-break',msg);
    });
    client3.subscribe('da-break');
  });

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题