status-react/test-resources/override.js

30 lines
675 B
JavaScript

var Mocks = require('../target/mocks/mocks.js');
var Module = require('module');
const originalLoader = Module._load;
/*
Hook `require` so that RN abuse of require does not break when running tests in nodejs.
*/
Module._load = function hookedLoader(request, parent, isMain) {
if (request.match(/.jpeg|.jpg|.png$/)) {
return { uri: request };
}
return originalLoader(request, parent, isMain);
};
var originalRequire = Module.prototype.require;
Module.prototype.require = function(req){
module = Mocks.mocks(req);
if (module == null) {
return originalRequire.apply(this, arguments);
}
else {
return module;
}
};