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

Merge pull request #6961 from kirrg001/improvement/add-not-existing-module-mock-fns

improvement: add mocks helper module for test env
This commit is contained in:
Hannah Wolfe 2016-06-10 10:18:44 +01:00 committed by GitHub
commit d341263934
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,
@ -600,6 +601,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;
};