1 | #!/usr/bin/env ts-node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | import { test } from 'tap'
|
23 | import sinon from 'sinon'
|
24 |
|
25 | import { PuppetMock } from 'wechaty-puppet-mock'
|
26 |
|
27 | import {
|
28 | Wechaty,
|
29 | } from './wechaty'
|
30 | import { WechatyPlugin } from './plugin'
|
31 |
|
32 | void test('Wechaty Plugin uninstaller should be called after wechaty.stop()', async t => {
|
33 | const spyPluginInstall = sinon.spy()
|
34 | const spyPluginUninstall = sinon.spy()
|
35 |
|
36 | const bot = new Wechaty({ puppet: new PuppetMock() })
|
37 |
|
38 | const plugin: WechatyPlugin = (_bot: Wechaty) => {
|
39 | spyPluginInstall()
|
40 | return () => {
|
41 | spyPluginUninstall()
|
42 | }
|
43 | }
|
44 |
|
45 | t.ok(spyPluginInstall.notCalled, 'should be clean for install spy')
|
46 | t.ok(spyPluginUninstall.notCalled, 'should be clean for uninstall spy')
|
47 |
|
48 | bot.use(plugin)
|
49 | t.ok(spyPluginInstall.called, 'should called install spy after use()')
|
50 | t.ok(spyPluginUninstall.notCalled, 'should not call uninstall spy after use()')
|
51 |
|
52 | await bot.start()
|
53 | await bot.stop()
|
54 |
|
55 | t.ok(spyPluginUninstall.called, 'should called uninstall spy after stop()')
|
56 | })
|