-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
var should = require('chai').should(); | ||
|
||
describe('Hexo', function(){ | ||
// | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
var should = require('chai').should(); | ||
var fs = require('hexo-fs'); | ||
var pathFn = require('path'); | ||
|
||
describe('Load plugins', function(){ | ||
var Hexo = require('../../../lib/hexo'); | ||
var hexo = new Hexo(pathFn.join(__dirname, 'plugin_test'), {silent: true}); | ||
var loadPlugins = require('../../../lib/hexo/load_plugins'); | ||
|
||
var script = [ | ||
'hexo._script_test = {', | ||
' filename: __filename,', | ||
' dirname: __dirname,', | ||
' module: module,', | ||
' require: require', | ||
'}' | ||
].join('\n'); | ||
|
||
function validate(path){ | ||
var result = hexo._script_test; | ||
|
||
result.filename = path; | ||
result.dirname = pathFn.dirname(path); | ||
result.module.id = path; | ||
result.module.filename = path; | ||
|
||
delete hexo._script_test; | ||
} | ||
|
||
hexo.env.init = true; | ||
hexo.theme_script_dir = pathFn.join(hexo.base_dir, 'themes', 'test', 'scripts'); | ||
|
||
before(function(){ | ||
return fs.mkdir(hexo.base_dir); | ||
}); | ||
|
||
after(function(){ | ||
return fs.rmdir(hexo.base_dir); | ||
}); | ||
|
||
it('load plugins', function(){ | ||
var path = pathFn.join(hexo.plugin_dir, 'hexo-plugin-test', 'index.js'); | ||
|
||
return fs.writeFile(path, script).then(function(){ | ||
return loadPlugins(hexo); | ||
}).then(function(){ | ||
validate(path); | ||
return fs.unlink(path); | ||
}); | ||
}); | ||
|
||
it('ignore plugins whose name is not started with "hexo-"', function(){ | ||
var script = 'hexo._script_test = true'; | ||
var path = pathFn.join(hexo.plugin_dir, 'another-plugin', 'index.js'); | ||
|
||
return fs.writeFile(path, script).then(function(){ | ||
return loadPlugins(hexo); | ||
}).then(function(){ | ||
should.not.exist(hexo._script_test); | ||
return fs.unlink(path); | ||
}); | ||
}); | ||
|
||
it('load scripts', function(){ | ||
var path = pathFn.join(hexo.script_dir, 'test.js'); | ||
|
||
return fs.writeFile(path, script).then(function(){ | ||
return loadPlugins(hexo); | ||
}).then(function(){ | ||
validate(path); | ||
return fs.unlink(path); | ||
}); | ||
}); | ||
|
||
it('load theme scripts', function(){ | ||
var path = pathFn.join(hexo.theme_script_dir, 'test.js'); | ||
|
||
return fs.writeFile(path, script).then(function(){ | ||
return loadPlugins(hexo); | ||
}).then(function(){ | ||
validate(path); | ||
return fs.unlink(path); | ||
}); | ||
}); | ||
|
||
it('don\'t load plugins in safe mode', function(){ | ||
var script = 'hexo._script_test = true'; | ||
var path = pathFn.join(hexo.script_dir, 'test.js'); | ||
|
||
return fs.writeFile(path, script).then(function(){ | ||
hexo.env.safe = true; | ||
return loadPlugins(hexo); | ||
}).then(function(){ | ||
hexo.env.safe = false; | ||
should.not.exist(hexo._script_test); | ||
return fs.unlink(path); | ||
}); | ||
}); | ||
}); |