提交 6d3f9eb0 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

fix unit tests

上级 f24d12b9
......@@ -2,6 +2,7 @@
// tslint:disable:no-shadowed-variable
import test from 'blue-tape'
import sinon from 'sinon'
import { MemoryCard } from 'memory-card'
......@@ -11,6 +12,10 @@ import {
} from './config'
class PadchatManagerTest extends PadchatManager {
public onSocket(payload: any) {
return super.onSocket(payload)
}
public async initCache(token: string, selfId: string) {
return super.initCache(
token,
......@@ -92,6 +97,8 @@ test('PadchatManager() stop many instances for the same time', async t => {
const MAX_NUM = 3
const managerList = [] as PadchatManagerTest[]
const sandbox = sinon.createSandbox()
for (let i = 0; i < MAX_NUM; i++ ) {
const manager = new PadchatManagerTest({
memory : new MemoryCard(),
......@@ -103,18 +110,20 @@ test('PadchatManager() stop many instances for the same time', async t => {
managerList.push(manager)
}
const releaseFutureList = [] as Promise<void>[]
const stopFutureList = [] as Promise<void>[]
for (let i = 0; i < MAX_NUM; i++) {
const manager = managerList[i]
const future = manager.stop()
releaseFutureList.push(future)
stopFutureList.push(future)
}
try {
await Promise.all(releaseFutureList)
await Promise.all(stopFutureList)
t.pass('stop' + MAX_NUM + ' at the same time success')
} catch (e) {
t.fail(e)
}
sandbox.restore()
})
......@@ -116,6 +116,10 @@ export class PadchatRpc extends EventEmitter {
throw new Error('socket had not been opened yet!')
}
this.jsonRpc.on('error', () => {
// TypeError: Cannot read property 'resolve' of undefined
// https://github.com/JsCommunity/json-rpc-peer/issues/52
})
this.jsonRpc.on('data', (buffer: string | Buffer) => {
// log.silly('PadchatRpc', 'initJsonRpc() jsonRpc.on(data)')
......
......@@ -539,12 +539,15 @@ export class Wechaty extends Accessory implements Sayable {
const eventNameList: PuppetEventName[] = Object.keys(PUPPET_EVENT_DICT) as any
for (const eventName of eventNameList) {
log.verbose('Wechaty', 'initPuppetEventBridge() puppet.on(%s) registered', eventName)
// /// e as any ??? Maybe this is a bug of TypeScript v2.5.3
// puppet.on(event as any, (...args: any[]) => {
// this.emit(event, ...args)
// })
switch (eventName) {
case 'dong':
puppet.removeAllListeners('dong')
puppet.on('dong', data => {
this.emit('dong', data)
})
break
case 'error':
puppet.removeAllListeners('error')
puppet.on('error', error => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册