diff --git a/game-server/test/app.test.ts b/game-server/test/app.test.ts index 66b1b4eb6..8cfb58975 100644 --- a/game-server/test/app.test.ts +++ b/game-server/test/app.test.ts @@ -1,48 +1,9 @@ import 'mocha'; -import { PinusWSClient, PinusWSClientEvent } from 'pinus-robot-plugin'; +import { PinusWSClient } from 'pinus-robot-plugin'; import { expect } from 'chai'; +import { Client } from './Client'; describe('test zyz login', function() { - // it('异步请求应该返回一个对象', function(done){ - // request - // .get('https://api.github.com') - // .end(function(err, res){ - // expect(res).to.be.an('object'); - // done(); - // }); - // }); - var pinusClient; - const loginParms = {serverId: 1}; - - beforeEach(function(done) { - pinusClient = new PinusWSClient(); - pinusClient.on(PinusWSClientEvent.EVENT_IO_ERROR, (event) => { - // 错误处理 - // console.error('error', event); - done(); - }); - pinusClient.on(PinusWSClientEvent.EVENT_CLOSE, function(event) { - // 关闭处理 - // console.error('close', event); - done(); - }); - pinusClient.on(PinusWSClientEvent.EVENT_HEART_BEAT_TIMEOUT, function(event) { - // 心跳timeout - // console.error('heart beat timeout', event); - }); - pinusClient.on(PinusWSClientEvent.EVENT_KICK, function(event) { - // 踢出 - // console.error('kick', event); - }); - let host = '127.0.0.1'; - let port = '3050'; - pinusClient.init({ - host: host, - port: port - }, (data) => { - // 连接成功执行函数 - done(); - }); - }); + let pinusClient: PinusWSClient; afterEach(function(done) { pinusClient.disconnect(); @@ -50,17 +11,12 @@ describe('test zyz login', function() { }); it('登录测试', function(done) { - expect(1).equal(1); - pinusClient.request('connector.entryHandler.debugQueryToken', {tel: '13911134885', magicWord: 'zyz666server518'}, (res) => { - expect(res).to.be.an('object'); - expect(res.data).to.be.an('object'); - expect(res.data.token).to.be.an('string'); - pinusClient.request('connector.entryHandler.enter', {...loginParms, ...res.data}, (ret) => { - expect(ret).to.be.an('object'); - expect(ret.code).equal(0); - // 消息回调 - done(); - }); - }); + const c = new Client(); + setTimeout(() => { + expect(c.client).to.be.an('object'); + expect(c.roleInfo).to.be.an('object'); + pinusClient = c.client; + done(); + }, 500); }); }); diff --git a/game-server/test/comBattle.test.ts b/game-server/test/comBattle.test.ts index 5d8b4d388..9128ed0a8 100644 --- a/game-server/test/comBattle.test.ts +++ b/game-server/test/comBattle.test.ts @@ -1,7 +1,7 @@ import { Client } from './Client'; import { COM_BTL_QUALITY } from './../app/consts/constModules/itemConst'; import 'mocha'; -import { PinusWSClient, PinusWSClientEvent } from 'pinus-robot-plugin'; +import { PinusWSClient } from 'pinus-robot-plugin'; import { expect } from 'chai'; describe('寻宝创建队伍', function() { var pinusClient: PinusWSClient; diff --git a/game-server/test/guild.test.ts b/game-server/test/guild.test.ts index f27cfa7be..b1b9f66fd 100644 --- a/game-server/test/guild.test.ts +++ b/game-server/test/guild.test.ts @@ -1,63 +1,20 @@ import 'mocha'; -import { PinusWSClient, PinusWSClientEvent } from 'pinus-robot-plugin'; +import { PinusWSClient } from 'pinus-robot-plugin'; import { expect } from 'chai'; +import { Client } from './Client'; describe('军团测试', function() { - // it('异步请求应该返回一个对象', function(done){ - // request - // .get('https://api.github.com') - // .end(function(err, res){ - // expect(res).to.be.an('object'); - // done(); - // }); - // }); - var pinusClient; - var roleInfo; + let pinusClient: PinusWSClient; let guildList; - const loginParms = {serverId: 1}; beforeEach(function(done) { - pinusClient = new PinusWSClient(); - pinusClient.on(PinusWSClientEvent.EVENT_IO_ERROR, (event) => { - // 错误处理 - // console.error('error', event); + const c = new Client(); + const timer = setInterval(() => { + if (c.client) { + pinusClient = c.client; + clearInterval(timer); done(); - }); - pinusClient.on(PinusWSClientEvent.EVENT_CLOSE, function(event) { - // 关闭处理 - // console.error('close', event); - done(); - }); - pinusClient.on(PinusWSClientEvent.EVENT_HEART_BEAT_TIMEOUT, function(event) { - // 心跳timeout - // console.error('heart beat timeout', event); - }); - pinusClient.on(PinusWSClientEvent.EVENT_KICK, function(event) { - // 踢出 - // console.error('kick', event); - }); - let host = '127.0.0.1'; - let port = '3050'; - pinusClient.init({ - host: host, - port: port - }, (data) => { - // 连接成功执行函数 - console.log('gate连接成功'); - // console.log('gate连接成功', data); - // done(); - pinusClient.request('connector.entryHandler.debugQueryToken', {tel: '13911134885', magicWord: 'zyz666server518'}, (res) => { - expect(res).to.be.an('object'); - expect(res.data).to.be.an('object'); - expect(res.data.token).to.be.an('string'); - pinusClient.request('connector.entryHandler.enter', {...loginParms, ...res.data}, (ret) => { - // 消息回调 - console.log('connector返回'); - // console.log('connector返回', JSON.stringify(ret)); - roleInfo = ret.role; - done(); - }); - }); - }); + } + }, 500); }); afterEach(function(done) {