@juzi/wechaty
Version:
Wechaty is a RPA SDK for Chatbot Makers.
70 lines • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
*
* @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
* Wechaty Contributors <https://github.com/wechaty>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
const tstest_1 = require("tstest");
const wechaty_puppet_mock_1 = require("@juzi/wechaty-puppet-mock");
const wechaty_builder_js_1 = require("./wechaty-builder.js");
const plugin_js_1 = require("./plugin.js");
/**
*
* Huan(202111): we are not remove plugins in the `stop()` method.
* @see https://github.com/wechaty/wechaty/issues/2282#issuecomment-966008175
*
* TODO: make sure to not remove or remote, then remove this comment
*
*/
(0, tstest_1.test)('Wechaty Plugin uninstaller should be called after wechaty.stop()', async (t) => {
const spyPluginInstall = tstest_1.sinon.spy();
const spyPluginUninstall = tstest_1.sinon.spy();
const bot = wechaty_builder_js_1.WechatyBuilder.build({ puppet: new wechaty_puppet_mock_1.PuppetMock() });
const plugin = (_bot) => {
spyPluginInstall();
return () => {
spyPluginUninstall();
};
};
t.ok(spyPluginInstall.notCalled, 'should be clean for install spy');
t.ok(spyPluginUninstall.notCalled, 'should be clean for uninstall spy');
const uninstaller = bot.use(plugin);
t.ok(spyPluginInstall.calledOnce, 'should called install spy right after use() before start()');
t.ok(spyPluginUninstall.notCalled, 'should not call uninstall spy after use()');
await bot.start();
t.ok(spyPluginInstall.calledOnce, 'should called install spy after start()');
t.ok(spyPluginUninstall.notCalled, 'should not call uninstall spy after start()');
spyPluginInstall.resetHistory();
await bot.stop();
t.ok(spyPluginInstall.notCalled, 'should not called with stop()');
await new Promise(setImmediate); // clean the event loop
t.ok(spyPluginUninstall.notCalled, 'should not call uninstall spy after stop()');
uninstaller();
t.ok(spyPluginUninstall.calledOnce, 'should called uninstall spy after call uninstaller()');
});
(0, tstest_1.test)('isWechatyPluginUninstaller()', async (t) => {
const FIXTURES = [
[undefined, false],
[() => { }, true],
];
for (const [uninstaller, expected] of FIXTURES) {
t.equal((0, plugin_js_1.isWechatyPluginUninstaller)(uninstaller), expected, `isWechatyPluginUninstaller(${uninstaller}) === ${expected}`);
}
});
//# sourceMappingURL=plugin.spec.js.map