@@ -4,6 +4,7 @@ const Hapi = require('hapi')
44const HemeraTestsuite = require ( 'hemera-testsuite' )
55const hemeraInternalSymbols = require ( 'nats-hemera/lib/symbols' )
66const Code = require ( 'code' )
7+ const Hp = require ( 'hemera-plugin' )
78const HapiHemera = require ( '../lib' )
89
910const expect = Code . expect
@@ -26,11 +27,10 @@ describe('Hemera plugin registration', function() {
2627 it ( 'Should be able to register a plugin' , async ( ) => {
2728 const server = new Hapi . Server ( )
2829
29- const myPlugin = async function myPlugin ( hemera , options ) { }
30-
31- myPlugin [ Symbol . for ( 'dependencies' ) ] = [ ]
32- myPlugin [ Symbol . for ( 'name' ) ] = 'myPlugin'
33- myPlugin [ Symbol . for ( 'options' ) ] = { a : 1 }
30+ const myPlugin = Hp ( async function myPlugin ( hemera , options ) { } , {
31+ name : 'myPlugin' ,
32+ options : { a : 1 }
33+ } )
3434
3535 await server . register ( {
3636 plugin : HapiHemera ,
@@ -48,4 +48,35 @@ describe('Hemera plugin registration', function() {
4848
4949 await server . stop ( )
5050 } )
51+
52+ it ( 'Should be able to register a plugin with options' , async ( ) => {
53+ const server = new Hapi . Server ( )
54+
55+ const myPlugin = Hp (
56+ async function myPlugin ( hemera , options ) {
57+ expect ( options ) . to . be . equals ( { a : 1 , b : 2 } )
58+ } ,
59+ {
60+ name : 'myPlugin' ,
61+ options : { a : 1 }
62+ }
63+ )
64+
65+ await server . register ( {
66+ plugin : HapiHemera ,
67+ options : {
68+ plugins : [ { register : myPlugin , options : { b : 2 } } ] ,
69+ nats : {
70+ url : noAuthUrl
71+ }
72+ }
73+ } )
74+
75+ expect ( server . hemera ) . to . exist ( )
76+ expect ( server . hemera [ hemeraInternalSymbols . registeredPlugins ] ) . to . be . equals (
77+ [ 'myPlugin' ]
78+ )
79+
80+ await server . stop ( )
81+ } )
5182} )
0 commit comments