@@ -12,14 +12,20 @@ function mockTransports() {
1212 a . on ( 'message' , ( msg ) => {
1313 a . emit ( 'rpc' , msg ) ;
1414 } ) ;
15- a . send = ( msg ) => {
15+ a . send = ( msg , config ) => {
1616 b . emit ( 'message' , msg ) ;
17+ if ( config ) {
18+ b . emit ( 'config' , config ) ;
19+ }
1720 } ;
1821
1922 b . on ( 'message' , ( msg ) => {
2023 b . emit ( 'rpc' , msg ) ;
2124 } ) ;
22- b . send = ( msg ) => {
25+ b . send = ( msg , config ) => {
26+ if ( config ) {
27+ a . emit ( 'config' , config ) ;
28+ }
2329 a . emit ( 'message' , msg ) ;
2430 } ;
2531
@@ -139,6 +145,46 @@ describe('rawr', () => {
139145 clientB . notifiers . doSomething ( 'testing_notification' ) ;
140146 } ) ;
141147
148+ it ( 'client should have notifiersExt method' , ( ) => {
149+ const { a } = mockTransports ( ) ;
150+ const client = rawr ( { transport : a } ) ;
151+ client . should . have . property ( 'notifiersExt' ) ;
152+ ( typeof client . notifiersExt ) . should . equal ( 'object' ) ;
153+ } ) ;
154+
155+ it ( 'client should be able to send a notification with notifiersExt' , ( done ) => {
156+ const { a, b } = mockTransports ( ) ;
157+ const clientA = rawr ( { transport : a } ) ;
158+ const clientB = rawr ( { transport : b } ) ;
159+
160+ clientA . notifications . ondoSomething ( ( someData ) => {
161+ someData . should . equal ( 'testing_notification_ext' ) ;
162+ done ( ) ;
163+ } ) ;
164+
165+ clientB . notifiersExt . doSomething ( 'testing_notification_ext' ) ;
166+ } ) ;
167+
168+ it ( 'client should pass config to transport when using notifiersExt' , ( done ) => {
169+ const { a, b } = mockTransports ( ) ;
170+ const clientA = rawr ( { transport : a } ) ;
171+ const clientB = rawr ( { transport : b } ) ;
172+
173+ let receivedConfig = false ;
174+ a . on ( 'config' , ( config ) => {
175+ config . should . deep . equal ( { postMessageOptions : { transfer : [ 'test' ] } } ) ;
176+ receivedConfig = true ;
177+ } ) ;
178+
179+ clientA . notifications . ondoConfigTest ( ( someData ) => {
180+ someData . should . equal ( 'config_test' ) ;
181+ receivedConfig . should . equal ( true ) ;
182+ done ( ) ;
183+ } ) ;
184+
185+ clientB . notifiersExt . doConfigTest ( 'config_test' , { postMessageOptions : { transfer : [ 'test' ] } } ) ;
186+ } ) ;
187+
142188 it ( 'client should fail on a configured timeout' , async ( ) => {
143189 const { a, b } = mockTransports ( ) ;
144190 const clientA = rawr ( { transport : a , handlers : { slowFunction, hi } } ) ;
0 commit comments