0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

improvement: add mocks helper module for test env

no issue
- add methods to mock/unmock not existent files
This commit is contained in:
kirrg001 2016-06-10 07:20:13 +02:00
parent 6826a6516b
commit 27d8eb5e70
3 changed files with 24 additions and 0 deletions

View file

@ -14,6 +14,7 @@ var Promise = require('bluebird'),
filterData = require('./fixtures/filter-param'),
API = require('./api'),
fork = require('./fork'),
mocks = require('./mocks'),
config = require('../../server/config'),
fixtures,
@ -596,6 +597,8 @@ module.exports = {
initData: initData,
clearData: clearData,
mocks: mocks,
fixtures: fixtures,
DataGenerator: DataGenerator,

View file

@ -0,0 +1 @@
exports.utils = require('./utils');

View file

@ -0,0 +1,20 @@
var Module = require('module'),
originalRequireFn = Module.prototype.require;
/**
* helper fn to mock non existent modules
* mocks.utils.mockNotExistingModule(/pattern/, mockedModule)
*/
exports.mockNotExistingModule = function mockNotExistingModule(modulePath, module) {
Module.prototype.require = function (path) {
if (path.match(modulePath)) {
return module;
}
return originalRequireFn.apply(this, arguments);
};
};
exports.unmockNotExistingModule = function unmockNotExistingModule() {
Module.prototype.require = originalRequireFn;
};