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:
parent
6826a6516b
commit
27d8eb5e70
3 changed files with 24 additions and 0 deletions
|
@ -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,
|
||||
|
|
1
core/test/utils/mocks/index.js
Normal file
1
core/test/utils/mocks/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
exports.utils = require('./utils');
|
20
core/test/utils/mocks/utils.js
Normal file
20
core/test/utils/mocks/utils.js
Normal 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;
|
||||
};
|
Loading…
Add table
Reference in a new issue