@@ -79,6 +79,21 @@ describe("mosca.Server", function() {
79
79
} ) ;
80
80
}
81
81
82
+ it ( "should pass itself in the callback" , function ( done ) {
83
+ secondInstance = new mosca . Server ( moscaSettings ( ) , function ( err , server ) {
84
+ expect ( server === secondInstance ) . to . be . true ;
85
+ done ( ) ;
86
+ } ) ;
87
+ } ) ;
88
+
89
+ it ( "should allow to be called like a function" , function ( done ) {
90
+ var func = mosca . Server ;
91
+ secondInstance = func ( moscaSettings ( ) , function ( err , server ) {
92
+ expect ( server === secondInstance ) . to . be . true ;
93
+ done ( ) ;
94
+ } ) ;
95
+ } ) ;
96
+
82
97
it ( "should support connecting and disconnecting" , function ( done ) {
83
98
buildClient ( done , function ( client ) {
84
99
@@ -626,7 +641,9 @@ describe("mosca.Server", function() {
626
641
type : "mqtt"
627
642
} ;
628
643
settings . port = nextPort ( ) ;
629
- secondInstance = new mosca . Server ( settings , cb ) ;
644
+ secondInstance = new mosca . Server ( settings , function ( ) {
645
+ cb ( ) ;
646
+ } ) ;
630
647
} ,
631
648
632
649
function ( cb ) {
@@ -737,7 +754,9 @@ describe("mosca.Server", function() {
737
754
type : "mqtt"
738
755
} ;
739
756
settings . port = settings . port + 1000 ;
740
- secondInstance = new mosca . Server ( settings , cb ) ;
757
+ secondInstance = new mosca . Server ( settings , function ( ) {
758
+ cb ( ) ;
759
+ } ) ;
741
760
} ,
742
761
743
762
function ( cb ) {
@@ -756,61 +775,26 @@ describe("mosca.Server", function() {
756
775
] ) ;
757
776
} ) ;
758
777
759
- it ( "should support specifying an Ascoltatore instead of backend options in a tree-based topology" , function ( done ) {
760
- var d = donner ( 2 , done ) ;
778
+ it ( "should support specifying an Ascoltatore instead of backend options" , function ( done ) {
761
779
762
780
async . waterfall ( [
763
781
764
- function ( cb ) {
765
- buildAndConnect ( d , function ( client1 ) {
766
- cb ( null , client1 ) ;
767
- } ) ;
768
- } ,
769
-
770
- function ( client1 , cb ) {
771
- client1 . on ( "publish" , function ( packet ) {
772
- expect ( packet . payload ) . to . be . eql ( "some data" ) ;
773
- client1 . disconnect ( ) ;
774
- } ) ;
775
-
776
- var subscriptions = [ {
777
- topic : "hello/#" ,
778
- qos : 0
779
- }
780
- ] ;
781
-
782
- client1 . subscribe ( {
783
- subscriptions : subscriptions ,
784
- messageId : 42
785
- } ) ;
786
- client1 . on ( "suback" , function ( ) {
787
- cb ( null ) ;
788
- } ) ;
789
- } ,
790
-
791
782
function ( cb ) {
792
783
settings . ascoltatore = ascoltatori . build ( {
793
- port : settings . port ,
794
- type : "mqtt" ,
795
784
json : false
796
785
} ) ;
797
786
settings . port = settings . port + 1000 ;
798
- secondInstance = new mosca . Server ( settings , cb ) ;
787
+ mosca . Server ( settings , cb ) ;
799
788
} ,
800
789
801
- function ( cb ) {
802
- buildAndConnect ( d , function ( client2 ) {
803
- cb ( null , client2 ) ;
804
- } ) ;
805
- } ,
806
-
807
- function ( client2 , cb ) {
808
- client2 . publish ( {
809
- topic : "hello/world" ,
810
- payload : "some data"
790
+ function ( server , cb ) {
791
+ secondInstance = server ;
792
+ buildAndConnect ( done , function ( client ) {
793
+ client . disconnect ( ) ;
794
+ cb ( null ) ;
811
795
} ) ;
812
- client2 . disconnect ( ) ;
813
796
}
797
+
814
798
] ) ;
815
799
} ) ;
816
800
0 commit comments