11import { bigIntUtils } from '@hathor/wallet-lib' ;
2- import { handleMessage } from '../../src/plugins/child' ;
2+ import { handleMessage , loadPlugins } from '../../src/plugins/child' ;
33import { notificationBus , EVENTBUS_EVENT_NAME } from '../../src/services/notification.service' ;
4+ import * as loggerModule from '../../src/logger' ;
45
56jest . mock ( '../../src/services/notification.service' , ( ) => ( {
67 notificationBus : {
@@ -9,6 +10,34 @@ jest.mock('../../src/services/notification.service', () => ({
910 EVENTBUS_EVENT_NAME : 'eventbus_event' ,
1011} ) ) ;
1112
13+ describe ( 'loadPlugins' , ( ) => {
14+ it ( 'should warn and skip unknown plugins' , async ( ) => {
15+ const mockWarn = jest . fn ( ) ;
16+ jest . spyOn ( loggerModule , 'buildAppLogger' ) . mockReturnValue ( { warn : mockWarn } ) ;
17+
18+ const plugins = await loadPlugins ( [ 'nonexistent_plugin' ] , { } ) ;
19+
20+ expect ( mockWarn ) . toHaveBeenCalledWith ( 'Unable to find plugin nonexistent_plugin, skipping.' ) ;
21+ expect ( plugins ) . toEqual ( [ ] ) ;
22+ } ) ;
23+
24+ it ( 'should load known hathor plugins' , async ( ) => {
25+ const plugins = await loadPlugins ( [ 'debug' ] , { } ) ;
26+
27+ expect ( plugins ) . toHaveLength ( 1 ) ;
28+ expect ( plugins [ 0 ] ) . toHaveProperty ( 'eventHandler' ) ;
29+ } ) ;
30+
31+ it ( 'should load custom plugins from config' , async ( ) => {
32+ const plugins = await loadPlugins ( [ 'my_plugin' ] , {
33+ my_plugin : { name : 'debug' , file : 'hathor_debug.js' } ,
34+ } ) ;
35+
36+ expect ( plugins ) . toHaveLength ( 1 ) ;
37+ expect ( plugins [ 0 ] ) . toHaveProperty ( 'eventHandler' ) ;
38+ } ) ;
39+ } ) ;
40+
1241describe ( 'handleMessage' , ( ) => {
1342 afterEach ( ( ) => {
1443 jest . clearAllMocks ( ) ;
0 commit comments