dees-comms/test/test.both.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-10-06 15:56:00 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
2022-03-25 13:17:13 +00:00
import * as deesComms from '../ts/index.js';
2020-10-06 15:56:00 +00:00
let deesCommsTest: deesComms.DeesComms;
2022-03-29 11:14:10 +00:00
let deesCommsTest2: deesComms.DeesComms;
2020-10-06 15:56:00 +00:00
2020-10-06 17:18:20 +00:00
tap.test('first test', async (tools) => {
2020-10-06 15:56:00 +00:00
deesCommsTest = new deesComms.DeesComms();
2022-03-29 11:14:10 +00:00
deesCommsTest2 = new deesComms.DeesComms();
2022-03-29 08:01:50 +00:00
let counter = 1;
2022-03-29 11:14:10 +00:00
deesCommsTest2.createTypedHandler<any>('test', async (requestData) => {
2022-03-29 08:01:50 +00:00
console.log(`got the request ${counter++}`);
2020-12-21 12:07:34 +00:00
return { hitheretoo: `greetings to ${requestData.hithere}` };
2020-10-06 17:18:20 +00:00
});
// lets fire a request
const typedrequest = deesCommsTest.createTypedRequest<any>('test');
2020-10-06 21:49:03 +00:00
const result = await typedrequest.fire({
2020-12-21 12:07:34 +00:00
hithere: 'hello',
2020-10-06 17:18:20 +00:00
});
2020-10-06 21:49:03 +00:00
console.log(JSON.stringify(result));
2022-03-29 08:01:50 +00:00
// lets fire a request
const typedrequest2 = deesCommsTest.createTypedRequest<any>('test2');
// TODO: return response after timeout
/* const result2 = await typedrequest2.fire({
hithere: 'hello',
});
console.log(JSON.stringify(result2)); */
2020-10-06 15:56:00 +00:00
});
2022-03-29 11:18:09 +00:00
tap.test('should end on nodejs', async (toolsArg) => {
if (globalThis.process) {
toolsArg.delayFor(2000).then(() => globalThis.process.exit(0));
}
})
2020-10-06 15:56:00 +00:00
tap.start();