@@ -4,6 +4,7 @@ import Hexo from '../../../lib/hexo';
44import loadPlugins from '../../../lib/hexo/load_plugins' ;
55import BluebirdPromise from 'bluebird' ;
66import chai from 'chai' ;
7+ import { spy } from 'sinon' ;
78const should = chai . should ( ) ;
89
910describe ( 'Load plugins' , ( ) => {
@@ -93,6 +94,20 @@ describe('Load plugins', () => {
9394 } ) ;
9495 } ) ;
9596
97+ it ( 'fail to load plugins' , ( ) => {
98+ const logSpy = spy ( ) ;
99+ hexo . log . error = logSpy ;
100+ const name = 'hexo-plugin-test' ;
101+ const path = join ( hexo . plugin_dir , name , 'index.js' ) ;
102+ return BluebirdPromise . all ( [
103+ createPackageFile ( name ) ,
104+ writeFile ( path , 'throw new Error("test")' )
105+ ] ) . then ( ( ) => loadPlugins ( hexo ) ) . then ( ( ) => {
106+ logSpy . args [ 0 ] [ 1 ] . should . contains ( 'Plugin load failed: %s' ) ;
107+ logSpy . args [ 0 ] [ 2 ] . should . contains ( 'hexo-plugin-test' ) ;
108+ } ) ;
109+ } ) ;
110+
96111 it ( 'load async plugins' , ( ) => {
97112 const name = 'hexo-async-plugin-test' ;
98113 const path = join ( hexo . plugin_dir , name , 'index.js' ) ;
@@ -217,6 +232,20 @@ describe('Load plugins', () => {
217232 return unlink ( path ) ;
218233 } ) ;
219234
235+ it ( 'fail to load scripts' , async ( ) => {
236+ const logSpy = spy ( ) ;
237+ hexo . log . error = logSpy ;
238+ const path = join ( hexo . script_dir , 'test.js' ) ;
239+
240+ writeFile ( path , 'throw new Error("test")' ) ;
241+ await loadPlugins ( hexo ) ;
242+
243+ logSpy . args [ 0 ] [ 1 ] . should . contains ( 'Script load failed: %s' ) ;
244+ logSpy . args [ 0 ] [ 2 ] . should . contains ( 'test.js' ) ;
245+ return unlink ( path ) ;
246+ } ) ;
247+
248+
220249 it ( 'load theme scripts' , ( ) => {
221250 const path = join ( hexo . theme_script_dir , 'test.js' ) ;
222251
0 commit comments