@@ -12,12 +12,17 @@ vi.mock('../src/pluginManager.js', {spy: true})
1212vi . mock ( '@actions/core' , { spy : true } )
1313
1414describe ( 'loadPlugins' , ( ) => {
15- vi . spyOn ( dynamicImportModule , 'dynamicImport' ) . mockImplementation ( path => Promise . resolve ( path ) )
15+ let dynamicImportCallCount = 0
16+ vi . spyOn ( dynamicImportModule , 'dynamicImport' ) . mockImplementation ( ( ) => {
17+ dynamicImportCallCount ++
18+ return Promise . resolve ( { name : `plugin-${ dynamicImportCallCount } ` , default : vi . fn ( ) } )
19+ } )
1620 beforeEach ( ( ) => {
21+ dynamicImportCallCount = 0
1722 // @ts -expect-error - we don't need the full fs readdirsync
1823 // method signature here
19- vi . spyOn ( fs , 'readdirSync' ) . mockImplementation ( readPath => {
20- return [ readPath + '/plugin-1 ', readPath + '/plugin-2 ']
24+ vi . spyOn ( fs , 'readdirSync' ) . mockImplementation ( ( ) => {
25+ return [ 'folder-a ', 'folder-b ']
2126 } )
2227 vi . spyOn ( fs , 'lstatSync' ) . mockImplementation ( ( ) => {
2328 return {
@@ -61,4 +66,26 @@ describe('loadPlugins', () => {
6166 expect ( logSpy ) . toHaveBeenCalledWith ( pluginManager . abortError )
6267 } )
6368 } )
69+
70+ describe ( 'when built-in and custom plugins share the same name' , ( ) => {
71+ beforeEach ( ( ) => {
72+ // @ts -expect-error - we don't need the full fs readdirsync
73+ // method signature here
74+ vi . spyOn ( fs , 'readdirSync' ) . mockImplementation ( ( ) => {
75+ return [ 'reflow-scan' ]
76+ } )
77+ vi . spyOn ( dynamicImportModule , 'dynamicImport' ) . mockImplementation ( ( ) => {
78+ return Promise . resolve ( { name : 'reflow-scan' , default : vi . fn ( ) } )
79+ } )
80+ } )
81+
82+ it ( 'skips the duplicate and only loads the plugin once' , async ( ) => {
83+ pluginManager . clearCache ( )
84+ const infoSpy = vi . spyOn ( core , 'info' ) . mockImplementation ( ( ) => { } )
85+ const plugins = await pluginManager . loadPlugins ( )
86+ expect ( plugins . length ) . toBe ( 1 )
87+ expect ( plugins [ 0 ] . name ) . toBe ( 'reflow-scan' )
88+ expect ( infoSpy ) . toHaveBeenCalledWith ( 'Skipping duplicate plugin: reflow-scan' )
89+ } )
90+ } )
6491} )
0 commit comments