|
@@ -541,38 +541,73 @@ type myExporterIfc = {
|
541
|
541
|
|
542
|
542
|
describe("Class binding", ()=>{
|
543
|
543
|
|
|
544
|
+ let exporter1 : MyExporter
|
|
545
|
+ let serv : RPCServer
|
|
546
|
+ let sock: RPCSocket & myExporterIfc
|
|
547
|
+
|
544
|
548
|
class MyExporter implements RPCExporter<myExporterIfc>{
|
545
|
549
|
name = "MyExporter" as "MyExporter";
|
546
|
550
|
exportRPCs = () => [
|
547
|
551
|
this.myRPC
|
548
|
552
|
]
|
549
|
553
|
|
550
|
|
- myRPC = async () => "Hello World"
|
|
554
|
+ myRPC = async () => {
|
|
555
|
+ serv.setExporters([new MyOtherExporter])
|
|
556
|
+ return "Hello World"
|
|
557
|
+ }
|
|
558
|
+ }
|
|
559
|
+
|
|
560
|
+ class MyOtherExporter implements RPCExporter<myExporterIfc>{
|
|
561
|
+ name = "MyExporter" as "MyExporter";
|
|
562
|
+ exportRPCs = () => [
|
|
563
|
+ this.myRPC
|
|
564
|
+ ]
|
|
565
|
+
|
|
566
|
+ myRPC = async () => "Hello Borld"
|
551
|
567
|
|
552
|
568
|
}
|
553
|
|
- let serv: RPCServer,
|
554
|
|
- sock: RPCSocket & myExporterIfc,
|
555
|
|
- exporter: MyExporter
|
|
569
|
+
|
|
570
|
+ before(done => {
|
|
571
|
+ exporter1 = new MyExporter()
|
|
572
|
+ serv = new RPCServer(21004, [exporter1])
|
|
573
|
+ done()
|
|
574
|
+ })
|
|
575
|
+
|
|
576
|
+ beforeEach((done)=>{
|
556
|
577
|
|
557
|
|
- before((done)=>{
|
558
|
|
- exporter = new MyExporter()
|
559
|
|
- serv = new RPCServer(21004, [exporter])
|
560
|
578
|
const s = new RPCSocket(21004, 'localhost')
|
561
|
579
|
s.connect<myExporterIfc>().then(conn => {
|
562
|
580
|
sock = conn
|
563
|
581
|
done()
|
564
|
582
|
})
|
565
|
583
|
})
|
566
|
|
- after(() => {
|
|
584
|
+
|
|
585
|
+ afterEach(done => {
|
567
|
586
|
sock.destroy()
|
|
587
|
+ done()
|
|
588
|
+ })
|
|
589
|
+
|
|
590
|
+ after(() => {
|
568
|
591
|
serv.destroy()
|
569
|
592
|
})
|
570
|
593
|
|
571
|
594
|
it("binds correctly", (done)=>{
|
572
|
|
- sock['MyExporter'].myRPC().then(() => {
|
|
595
|
+ sock['MyExporter'].myRPC().then((res) => {
|
|
596
|
+ done(new Error(res))
|
|
597
|
+ }).catch(e => {
|
|
598
|
+ //job will time out because of setExporters
|
573
|
599
|
done()
|
574
|
600
|
})
|
575
|
601
|
})
|
|
602
|
+
|
|
603
|
+ it("changes exporters", (done) => {
|
|
604
|
+ sock['MyExporter'].myRPC().then((res) => {
|
|
605
|
+ if(res === "Hello Borld")
|
|
606
|
+ done()
|
|
607
|
+ else
|
|
608
|
+ done(new Error(res))
|
|
609
|
+ })
|
|
610
|
+ })
|
576
|
611
|
})
|
577
|
612
|
|
578
|
613
|
|