UNPKG

wechaty-puppet-service

Version:
70 lines 2.46 kB
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const tstest_1 = require("tstest"); const wechaty_puppet_mock_1 = require("wechaty-puppet-mock"); const get_port_1 = __importDefault(require("get-port")); const mod_js_1 = require("../src/mod.js"); const NIL_UUID_V4 = '00000000-0000-0000-0000-000000000000'; (0, tstest_1.test)('Integration testing', async (t) => { const PORT = await (0, get_port_1.default)(); const TOKEN = `insecure_${NIL_UUID_V4}`; const ENDPOINT = `0.0.0.0:${PORT}`; const DING = '__ding_data__'; /** * Puppet in Service */ const puppet = new wechaty_puppet_mock_1.PuppetMock(); const spyStart = tstest_1.sinon.spy(puppet, 'start'); const spyOn = tstest_1.sinon.spy(puppet, 'on'); const spyDing = tstest_1.sinon.spy(puppet, 'ding'); /** * Puppet Server */ const serverOptions = { endpoint: ENDPOINT, puppet: puppet, token: TOKEN, }; const puppetServer = new mod_js_1.PuppetServer(serverOptions); await puppetServer.start(); /** * Puppet Service Client */ const puppetOptions = { endpoint: ENDPOINT, token: TOKEN, }; const puppetService = new mod_js_1.PuppetService(puppetOptions); await puppetService.start(); t.ok(spyStart.called, 'should called the puppet server start() function'); const future = new Promise((resolve, reject) => { const offError = () => puppetService.off('error', reject); puppetService.once('dong', payload => { resolve(payload.data || ''); offError(); }); puppetService.once('error', e => { reject(e); offError(); }); }); puppetService.ding(DING); const result = await future; t.ok(spyOn.called, 'should called the puppet server on() function'); t.ok(spyDing.called, 'should called the puppet server ding() function'); t.equal(result, DING, 'should get a successful roundtrip for ding'); /** * Stop * 1. Puppet in Service * 2. Puppet Service Server * 3. Puppet Service Client * */ await puppetService.stop(); await puppetServer.stop(); }); //# sourceMappingURL=integration.spec.js.map