smartipc/test/test.ts

42 lines
1002 B
TypeScript
Raw Normal View History

2019-04-05 18:30:43 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
2019-04-08 17:42:23 +00:00
import * as smartipc from '../ts/index';
2019-04-05 18:30:43 +00:00
2019-04-08 17:42:23 +00:00
import * as smartspawn from '@pushrocks/smartspawn';
import * as smartpromise from '@pushrocks/smartpromise';
2019-04-09 10:30:12 +00:00
let serverIpc: smartipc.SmartIpc;
let clientIpc: smartipc.SmartIpc;
2019-04-08 17:42:23 +00:00
tap.test('should instantiate a valid instance', async () => {
2019-04-09 10:30:12 +00:00
serverIpc = new smartipc.SmartIpc({
2019-04-08 17:42:23 +00:00
ipcSpace: 'testSmartIpc',
type: 'server'
});
2019-04-09 10:30:12 +00:00
serverIpc.registerHandler({
keyword: 'hi',
handlerFunc: data => {
console.log(data);
}
});
await serverIpc.start();
2019-04-08 17:42:23 +00:00
});
2019-04-08 17:56:21 +00:00
tap.test('should create a client', async tools => {
2019-04-09 10:30:12 +00:00
clientIpc = new smartipc.SmartIpc({
2019-04-08 17:56:21 +00:00
ipcSpace: 'testSmartIpc',
type: 'client'
});
2019-04-09 10:30:12 +00:00
await clientIpc.start();
clientIpc.sendMessage('hi', { awesome: 'yes' });
2019-04-08 17:42:23 +00:00
});
2019-04-09 10:33:46 +00:00
tap.test('should terminate the smartipc process', async tools => {
2019-04-09 10:30:12 +00:00
await clientIpc.stop();
await serverIpc.stop();
2019-04-09 10:35:27 +00:00
tools.delayFor(2000).then(() => {
process.exit(0);
});
2019-04-09 10:30:12 +00:00
});
2019-04-08 17:56:21 +00:00
2019-04-08 17:42:23 +00:00
tap.start();