@@ -201,10 +201,91 @@ describe('test/app.test.ts', () => {
201201 expect ( plugin ) . toBeInstanceOf ( Plugin ) ;
202202 expect ( plugin . enable ) . toBeTruthy ( ) ;
203203 } ) ;
204- expect ( mockWarnFn ) . toBeCalledWith ( `Plugin plugin-d need have optional dependency: plugin-e .` ) ;
204+ expect ( mockWarnFn ) . toBeCalledWith ( `Plugin plugin-d need have optional dependency: plugin-c .` ) ;
205205
206206 // restore warn
207207 console . warn = originWarn ;
208208 } ) ;
209+
210+ it ( 'should not throw if optional dependence disabled' , async ( ) => {
211+ const mockPluginConfig = {
212+ 'plugin-c' : {
213+ enable : false ,
214+ path : path . resolve ( __dirname , `${ pluginPrefix } /plugin_c` ) ,
215+ manifest : {
216+ pluginMeta : {
217+ path : path . resolve ( __dirname , `${ pluginPrefix } /plugin_c/meta.js` ) ,
218+ extname : '.js' ,
219+ filename : 'meta.js' ,
220+ } ,
221+ } ,
222+ } ,
223+ 'plugin-d' : {
224+ enable : true ,
225+ path : path . resolve ( __dirname , `${ pluginPrefix } /plugin_d` ) ,
226+ manifest : {
227+ pluginMeta : {
228+ path : path . resolve ( __dirname , `${ pluginPrefix } /plugin_d/meta.js` ) ,
229+ extname : '.js' ,
230+ filename : 'meta.js' ,
231+ } ,
232+ } ,
233+ } ,
234+ } ;
235+
236+ // mock warn
237+ const originWarn = console . warn ;
238+ const mockWarnFn = jest . fn ( ) ;
239+ console . warn = mockWarnFn ;
240+ const pluginList = await PluginFactory . createFromConfig ( mockPluginConfig , {
241+ logger : new Logger ( ) ,
242+ } ) ;
243+ expect ( pluginList . length ) . toEqual ( 1 ) ;
244+ pluginList . forEach ( plugin => {
245+ expect ( plugin ) . toBeInstanceOf ( Plugin ) ;
246+ expect ( plugin . enable ) . toBeTruthy ( ) ;
247+ } ) ;
248+ expect ( mockWarnFn ) . toBeCalledWith ( `Plugin plugin-d need have optional dependency: plugin-c.` ) ;
249+
250+ // restore warn
251+ console . warn = originWarn ;
252+ } ) ;
253+
254+ it ( 'should calc order if optional dependence enabled' , async ( ) => {
255+ const mockPluginConfig = {
256+ 'plugin-d' : {
257+ enable : true ,
258+ path : path . resolve ( __dirname , `${ pluginPrefix } /plugin_d` ) ,
259+ manifest : {
260+ pluginMeta : {
261+ path : path . resolve ( __dirname , `${ pluginPrefix } /plugin_d/meta.js` ) ,
262+ extname : '.js' ,
263+ filename : 'meta.js' ,
264+ } ,
265+ } ,
266+ } ,
267+ 'plugin-c' : {
268+ enable : true ,
269+ path : path . resolve ( __dirname , `${ pluginPrefix } /plugin_c` ) ,
270+ manifest : {
271+ pluginMeta : {
272+ path : path . resolve ( __dirname , `${ pluginPrefix } /plugin_c/meta.js` ) ,
273+ extname : '.js' ,
274+ filename : 'meta.js' ,
275+ } ,
276+ } ,
277+ } ,
278+ } ;
279+
280+ const pluginList = await PluginFactory . createFromConfig ( mockPluginConfig , {
281+ logger : new Logger ( ) ,
282+ } ) ;
283+ expect ( pluginList . length ) . toEqual ( 2 ) ;
284+ pluginList . forEach ( plugin => {
285+ expect ( plugin ) . toBeInstanceOf ( Plugin ) ;
286+ expect ( plugin . enable ) . toBeTruthy ( ) ;
287+ } ) ;
288+ expect ( pluginList . map ( plugin => plugin . name ) ) . toStrictEqual ( [ 'plugin-c' , 'plugin-d' ] ) ;
289+ } ) ;
209290 } ) ;
210291} ) ;
0 commit comments