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

use mock puppet in smoke testing

上级 3bbd8033
#!/usr/bin/env ts-node
// tslint:disable:no-shadowed-variable
import test from 'blue-tape'
import { MemoryCard } from 'memory-card'
import { PuppetMock } from './puppet-mock'
class PuppetMockTest extends PuppetMock {
}
test('PuppetMock() restart without problem', async t => {
const puppet = new PuppetMockTest({
memory : new MemoryCard(),
})
try {
for (let i = 0; i < 3; i++) {
await puppet.start()
await puppet.stop()
t.pass('start/stop-ed at #' + i)
}
t.pass('PuppetMock() start/restart successed.')
} catch (e) {
t.fail(e)
}
})
......@@ -67,6 +67,8 @@ export interface MockRoomRawPayload {
export class PuppetMock extends Puppet {
private loopTimer?: NodeJS.Timer
constructor(
public options: PuppetOptions,
) {
......@@ -94,7 +96,7 @@ export class PuppetMock extends Puppet {
toId : 'xxx',
})
setInterval(() => {
this.loopTimer = setInterval(() => {
log.verbose('PuppetMock', `start() setInterval() pretending received a new message: ${MOCK_MSG_ID}`)
this.emit('message', MOCK_MSG_ID)
}, 3000)
......@@ -111,6 +113,11 @@ export class PuppetMock extends Puppet {
}
this.state.off('pending')
if (this.loopTimer) {
clearInterval(this.loopTimer)
}
// await some tasks...
this.state.off(true)
}
......
......@@ -3,7 +3,9 @@
import { Wechaty } from 'wechaty'
async function main() {
const bot = Wechaty.instance()
const bot = Wechaty.instance({
puppet: 'mock',
})
try {
await bot.start()
console.log(`Wechaty v${bot.version()} smoking test passed.`)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册