mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 12:53:13 +03:00
7f1d3ebc07
- move all test files from core/test to test/ - updated all imports and other references - all code inside of core/ is then application code - tests are correctly at the root level - consistent with other repos/projects Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
24 lines
631 B
JavaScript
24 lines
631 B
JavaScript
const Module = require('module');
|
|
const originalRequireFn = Module.prototype.require;
|
|
|
|
/**
|
|
* helper fn to mock non-existent modules
|
|
* mocks.modules.mockNonExistentModule(/pattern/, mockedModule)
|
|
*/
|
|
exports.mockNonExistentModule = (modulePath, module, error = false) => {
|
|
Module.prototype.require = function (path) {
|
|
if (path.match(modulePath)) {
|
|
if (error) {
|
|
throw module;
|
|
}
|
|
return module;
|
|
}
|
|
|
|
return originalRequireFn.apply(this, arguments);
|
|
};
|
|
};
|
|
|
|
exports.unmockNonExistentModule = () => {
|
|
Module.prototype.require = originalRequireFn;
|
|
};
|