@@ -66,10 +66,13 @@ describe("Settings", () => {
6666 expect ( tracer . verbose . calledWith ( "Registered 0 plugins" ) ) . toEqual ( true ) ;
6767 } ) ;
6868
69- it ( "should register function plugins" , async ( ) => {
70- const fooPlugin = ( ) => { } ;
69+ it ( "should register function plugins executing them passing the core" , async ( ) => {
70+ expect . assertions ( 3 ) ;
71+ const fooPlugin = sinon . spy ( ) ;
7172 plugins = new Plugins ( [ fooPlugin ] , coreInstance ) ;
7273 await plugins . register ( ) ;
74+ expect ( fooPlugin . calledWith ( coreInstance ) ) . toEqual ( true ) ;
75+ expect ( fooPlugin . callCount ) . toEqual ( 1 ) ;
7376 expect ( tracer . verbose . calledWith ( "Registered 1 plugins" ) ) . toEqual ( true ) ;
7477 } ) ;
7578
@@ -121,4 +124,142 @@ describe("Settings", () => {
121124 expect ( tracer . verbose . calledWith ( "Registered 3 plugins" ) ) . toEqual ( true ) ;
122125 } ) ;
123126 } ) ;
127+
128+ describe ( "init method" , ( ) => {
129+ it ( "should do nothing if there are no plugins to register" , async ( ) => {
130+ plugins = new Plugins ( null , coreInstance ) ;
131+ await plugins . register ( ) ;
132+ await plugins . init ( ) ;
133+ expect ( tracer . verbose . calledWith ( "Initializated 0 plugins" ) ) . toEqual ( true ) ;
134+ } ) ;
135+
136+ it ( "should init object plugins with an init property" , async ( ) => {
137+ expect . assertions ( 2 ) ;
138+ const fooPlugin = {
139+ init : sinon . spy ( )
140+ } ;
141+ plugins = new Plugins ( [ fooPlugin ] , coreInstance ) ;
142+ await plugins . register ( ) ;
143+ await plugins . init ( ) ;
144+ expect ( fooPlugin . init . callCount ) . toEqual ( 1 ) ;
145+ expect ( tracer . verbose . calledWith ( "Initializated 1 plugins" ) ) . toEqual ( true ) ;
146+ } ) ;
147+
148+ it ( "should accept init methods non returning a Promise" , async ( ) => {
149+ expect . assertions ( 1 ) ;
150+ const fooPlugin = {
151+ init : ( ) => true
152+ } ;
153+ const fooPlugin2 = {
154+ init : ( ) => Promise . resolve ( )
155+ } ;
156+ plugins = new Plugins ( [ fooPlugin , fooPlugin2 ] , coreInstance ) ;
157+ await plugins . register ( ) ;
158+ await plugins . init ( ) ;
159+ expect ( tracer . verbose . calledWith ( "Initializated 2 plugins" ) ) . toEqual ( true ) ;
160+ } ) ;
161+
162+ it ( "should catch init method errors" , async ( ) => {
163+ expect . assertions ( 1 ) ;
164+ const fooPlugin = {
165+ init : ( ) => {
166+ throw new Error ( ) ;
167+ }
168+ } ;
169+ const fooPlugin2 = {
170+ init : ( ) => Promise . resolve ( )
171+ } ;
172+ const fooPlugin3 = {
173+ init : ( ) => Promise . resolve ( )
174+ } ;
175+ plugins = new Plugins ( [ fooPlugin , fooPlugin2 , fooPlugin3 ] , coreInstance ) ;
176+ await plugins . register ( ) ;
177+ await plugins . init ( ) ;
178+ expect ( tracer . verbose . calledWith ( "Initializated 2 plugins" ) ) . toEqual ( true ) ;
179+ } ) ;
180+
181+ it ( "should accept plugins with no init method" , async ( ) => {
182+ expect . assertions ( 1 ) ;
183+ const fooPlugin = { } ;
184+ const fooPlugin2 = {
185+ init : ( ) => Promise . resolve ( )
186+ } ;
187+ const fooPlugin3 = {
188+ init : ( ) => Promise . resolve ( )
189+ } ;
190+ plugins = new Plugins ( [ fooPlugin , fooPlugin2 , fooPlugin3 ] , coreInstance ) ;
191+ await plugins . register ( ) ;
192+ await plugins . init ( ) ;
193+ expect ( tracer . verbose . calledWith ( "Initializated 2 plugins" ) ) . toEqual ( true ) ;
194+ } ) ;
195+ } ) ;
196+
197+ describe ( "start method" , ( ) => {
198+ it ( "should do nothing if there are no plugins to register" , async ( ) => {
199+ plugins = new Plugins ( null , coreInstance ) ;
200+ await plugins . register ( ) ;
201+ await plugins . start ( ) ;
202+ expect ( tracer . verbose . calledWith ( "Started 0 plugins" ) ) . toEqual ( true ) ;
203+ } ) ;
204+
205+ it ( "should start object plugins with an init property" , async ( ) => {
206+ expect . assertions ( 2 ) ;
207+ const fooPlugin = {
208+ start : sinon . spy ( )
209+ } ;
210+ plugins = new Plugins ( [ fooPlugin ] , coreInstance ) ;
211+ await plugins . register ( ) ;
212+ await plugins . start ( ) ;
213+ expect ( fooPlugin . start . callCount ) . toEqual ( 1 ) ;
214+ expect ( tracer . verbose . calledWith ( "Started 1 plugins" ) ) . toEqual ( true ) ;
215+ } ) ;
216+
217+ it ( "should accept start methods non returning a Promise" , async ( ) => {
218+ expect . assertions ( 1 ) ;
219+ const fooPlugin = {
220+ start : ( ) => true
221+ } ;
222+ const fooPlugin2 = {
223+ start : ( ) => Promise . resolve ( )
224+ } ;
225+ plugins = new Plugins ( [ fooPlugin , fooPlugin2 ] , coreInstance ) ;
226+ await plugins . register ( ) ;
227+ await plugins . start ( ) ;
228+ expect ( tracer . verbose . calledWith ( "Started 2 plugins" ) ) . toEqual ( true ) ;
229+ } ) ;
230+
231+ it ( "should catch start method errors" , async ( ) => {
232+ expect . assertions ( 1 ) ;
233+ const fooPlugin = {
234+ start : ( ) => {
235+ throw new Error ( ) ;
236+ }
237+ } ;
238+ const fooPlugin2 = {
239+ start : ( ) => Promise . resolve ( )
240+ } ;
241+ const fooPlugin3 = {
242+ start : ( ) => Promise . resolve ( )
243+ } ;
244+ plugins = new Plugins ( [ fooPlugin , fooPlugin2 , fooPlugin3 ] , coreInstance ) ;
245+ await plugins . register ( ) ;
246+ await plugins . start ( ) ;
247+ expect ( tracer . verbose . calledWith ( "Started 2 plugins" ) ) . toEqual ( true ) ;
248+ } ) ;
249+
250+ it ( "should accept plugins with no start method" , async ( ) => {
251+ expect . assertions ( 1 ) ;
252+ const fooPlugin = { } ;
253+ const fooPlugin2 = {
254+ start : ( ) => Promise . resolve ( )
255+ } ;
256+ const fooPlugin3 = {
257+ start : ( ) => Promise . resolve ( )
258+ } ;
259+ plugins = new Plugins ( [ fooPlugin , fooPlugin2 , fooPlugin3 ] , coreInstance ) ;
260+ await plugins . register ( ) ;
261+ await plugins . start ( ) ;
262+ expect ( tracer . verbose . calledWith ( "Started 2 plugins" ) ) . toEqual ( true ) ;
263+ } ) ;
264+ } ) ;
124265} ) ;
0 commit comments