mirror of https://github.com/status-im/metro.git
Add mocks for packages to resolution responses
Summary: Right now, a mock called `debug.js` shadows a node module called `debug`. When I made mocking more strict I didn't realize that it didn't include those mocks any more because requiring `debug` would result in a module like `debug/node.js` which doesn't have a mock associated with it. This diff changes it so it looks at the associated `package.json` to match the name up to mocks. This is the least invasive non-breaking change I can make right now. Yes, mocking strategies are basically fucked but I don't want the haste2 integration to have even more breaking changes right now. Consider this code to be temporary, I'll fix this and make the mocking system more sane mid-term. public Reviewed By: davidaurelio Differential Revision: D2889198 fb-gh-sync-id: 58db852ed9acad830538245f7dc347365fe4de38
This commit is contained in:
parent
042dc4349a
commit
f2cb2355b2
|
@ -118,14 +118,21 @@ class ResolutionRequest {
|
||||||
).then((dependencies) => [depNames, dependencies])
|
).then((dependencies) => [depNames, dependencies])
|
||||||
).then(([depNames, dependencies]) => {
|
).then(([depNames, dependencies]) => {
|
||||||
if (allMocks) {
|
if (allMocks) {
|
||||||
return mod.getName().then(name => {
|
const list = [mod.getName()];
|
||||||
if (allMocks[name]) {
|
const pkg = mod.getPackage();
|
||||||
const mockModule =
|
if (pkg) {
|
||||||
this._moduleCache.getModule(allMocks[name]);
|
list.push(pkg.getName());
|
||||||
depNames.push(name);
|
}
|
||||||
dependencies.push(mockModule);
|
return Promise.all(list).then(names => {
|
||||||
mocks[name] = allMocks[name];
|
names.forEach(name => {
|
||||||
}
|
if (allMocks[name] && !mocks[name]) {
|
||||||
|
const mockModule =
|
||||||
|
this._moduleCache.getModule(allMocks[name]);
|
||||||
|
depNames.push(name);
|
||||||
|
dependencies.push(mockModule);
|
||||||
|
mocks[name] = allMocks[name];
|
||||||
|
}
|
||||||
|
});
|
||||||
return [depNames, dependencies];
|
return [depNames, dependencies];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -141,7 +148,7 @@ class ResolutionRequest {
|
||||||
// module backing them. If a dependency cannot be found but there
|
// module backing them. If a dependency cannot be found but there
|
||||||
// exists a mock with the desired ID, resolve it and add it as
|
// exists a mock with the desired ID, resolve it and add it as
|
||||||
// a dependency.
|
// a dependency.
|
||||||
if (allMocks && allMocks[name]) {
|
if (allMocks && allMocks[name] && !mocks[name]) {
|
||||||
const mockModule = this._moduleCache.getModule(allMocks[name]);
|
const mockModule = this._moduleCache.getModule(allMocks[name]);
|
||||||
mocks[name] = allMocks[name];
|
mocks[name] = allMocks[name];
|
||||||
return filteredPairs.push([name, mockModule]);
|
return filteredPairs.push([name, mockModule]);
|
||||||
|
|
Loading…
Reference in New Issue