mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
21 lines
597 B
JavaScript
21 lines
597 B
JavaScript
|
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;
|
||
|
};
|