测试:mocha 基础文件
This commit is contained in:
62
game-server/test/app.test.ts
Normal file
62
game-server/test/app.test.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'mocha';
|
||||
import { PinusWSClient, PinusWSClientEvent } from 'pinus-robot-plugin';
|
||||
import { expect } from 'chai';
|
||||
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;
|
||||
|
||||
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) => {
|
||||
// 连接成功执行函数
|
||||
console.log('gate连接成功', data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
pinusClient.disconnect();
|
||||
done();
|
||||
});
|
||||
|
||||
it('登录测试', function(done) {
|
||||
expect(1).equal(1);
|
||||
pinusClient.request('connector.entryHandler.enter', {token:'mgn0njiajb6kapid3eekvt7tssxelig9zi2oq2bzkxr4zzi9w9', serverId: 1} , (ret) => {
|
||||
// 消息回调
|
||||
console.log('connector返回', JSON.stringify(ret));
|
||||
expect(ret).to.be.an('object');
|
||||
expect(ret.code).equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
69
game-server/test/comBattle.test.ts
Normal file
69
game-server/test/comBattle.test.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
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;
|
||||
|
||||
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) => {
|
||||
// 连接成功执行函数
|
||||
console.log('gate连接成功', data);
|
||||
// done();
|
||||
pinusClient.request('connector.entryHandler.enter', {token:'mgn0njiajb6kapid3eekvt7tssxelig9zi2oq2bzkxr4zzi9w9', serverId: 1} , (ret) => {
|
||||
// 消息回调
|
||||
console.log('connector返回', JSON.stringify(ret));
|
||||
roleInfo = ret.role;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
pinusClient.disconnect();
|
||||
done();
|
||||
});
|
||||
|
||||
it('直接返回队伍', function(done) {
|
||||
pinusClient.request('battle.comBattleHandler.createTeam', {blueprtId: 33001, pub: true, ceLimit: 0}, (res) => {
|
||||
expect(res).to.be.an('object');
|
||||
expect(res.code).equal(0);
|
||||
expect(res.data).to.be.an('object');
|
||||
expect(res.data.teamCode).to.be.a('string');
|
||||
expect(res.data.roleStatus).to.be.an('array');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
12
game-server/test/pubUtils.test.ts
Normal file
12
game-server/test/pubUtils.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { resResult } from '../app/pubUtils/util';
|
||||
describe('测试 ts', function() {
|
||||
it('用例1', function() {
|
||||
const result = resResult({code: 0, simStr: 'hello'});
|
||||
console.log('ltc result: ', result);
|
||||
expect(result).to.be.an('object');
|
||||
expect(result.code).equal(0);
|
||||
expect(result.msg).equal('hello');
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user