diff --git a/src/puppet-padchat/padchat-manager.spec.ts b/src/puppet-padchat/padchat-manager.spec.ts index 1a1b7a583d22ec9ac431bd77c373a6d419e72d25..bcf972c3cca1839757532d0199a46377b94c53df 100755 --- a/src/puppet-padchat/padchat-manager.spec.ts +++ b/src/puppet-padchat/padchat-manager.spec.ts @@ -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[] + const stopFutureList = [] as Promise[] 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() }) diff --git a/src/puppet-padchat/padchat-rpc.ts b/src/puppet-padchat/padchat-rpc.ts index f6348a8c8517ccc711f5ecaac991d397667e00cc..2ff057fdcdf12819915ec2cca46895234a11de8f 100644 --- a/src/puppet-padchat/padchat-rpc.ts +++ b/src/puppet-padchat/padchat-rpc.ts @@ -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)') diff --git a/src/wechaty.ts b/src/wechaty.ts index d325728ddcf498a359f8d7e25800af2204c93c31..42e23605c10aa7e3120d81b3f82006b4610f4930 100644 --- a/src/wechaty.ts +++ b/src/wechaty.ts @@ -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 => {