diff --git a/game-server/test/Client.ts b/game-server/test/Client.ts new file mode 100644 index 000000000..b16c45a26 --- /dev/null +++ b/game-server/test/Client.ts @@ -0,0 +1,41 @@ +import { PinusWSClient } from 'pinus-robot-plugin'; +import { expect } from 'chai'; + +export class Client { + _client; + _roleInfo; + constructor(tel: string = '13911134885') { + this._client = new PinusWSClient(); + + let host = '127.0.0.1'; + let port = '3050'; + this._client.init({ + host: host, + port: port + }, (data) => { + // 连接成功执行函数 + console.log('gate连接成功'); + this._client.request('connector.entryHandler.debugQueryToken', {tel, magicWord: 'zyz666server518'}, (res) => { + expect(res).to.be.an('object'); + expect(res.data).to.be.an('object'); + expect(res.data.token).to.be.an('string'); + this._client.request('connector.entryHandler.enter', {serverId: 1, ...res.data}, (ret) => { + // 消息回调 + console.log('connector返回'); + expect(ret).to.be.an('object'); + expect(ret.data).to.be.an('object'); + expect(ret.data.role).to.be.an('object'); + this._roleInfo = ret.data.role; + }); + }); + }); + } + + get roleInfo() { + return this._roleInfo; + } + + get client() { + return this._client; + } +} \ No newline at end of file diff --git a/game-server/test/comBattle.test.ts b/game-server/test/comBattle.test.ts index 04bc4929e..5d8b4d388 100644 --- a/game-server/test/comBattle.test.ts +++ b/game-server/test/comBattle.test.ts @@ -1,66 +1,23 @@ +import { Client } from './Client'; import { COM_BTL_QUALITY } from './../app/consts/constModules/itemConst'; import 'mocha'; import { PinusWSClient, PinusWSClientEvent } from 'pinus-robot-plugin'; import { expect } from 'chai'; 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; + var pinusClient: PinusWSClient; - const loginParms = {serverId: 1}; const createTeamParms = {blueprtId: 33001, pub: true, ceLimit: 0}; const searchTeamParms = {qualityArr: COM_BTL_QUALITY}; 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) {