Files
smartipc/test/test.ts

42 lines
1019 B
TypeScript
Raw Normal View History

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