mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-02 23:05:01 +08:00
Support "free" mocks.
Summary: It's possible that a mock doesn't have an associated real module that it maps to. This is actually very common in www, where we have JS mocks for dynamic PHP JS modules. The implementation I chose seems like the smartest one for now: if a module cannot be resolved, we look up whether we have a mock with the same id. If we do, we just resolve it. That's it! And it also only does the minimum amount of resolution necessary. public Reviewed By: martinbigio Differential Revision: D2822277 fb-gh-sync-id: 7c9fbb6f69a0c0c85157c0650f5719d94a02410e
This commit is contained in:
committed by
facebook-github-bot-1
parent
e2641a237a
commit
801b83da2d
@@ -135,15 +135,25 @@ class ResolutionRequest {
|
||||
const filteredPairs = [];
|
||||
|
||||
dependencies.forEach((modDep, i) => {
|
||||
const name = depNames[i];
|
||||
if (modDep == null) {
|
||||
// It is possible to require mocks that don't have a real
|
||||
// module backing them. If a dependency cannot be found but there
|
||||
// exists a mock with the desired ID, resolve it and add it as
|
||||
// a dependency.
|
||||
if (mocks && mocks[name]) {
|
||||
const mockModule = this._moduleCache.getModule(mocks[name]);
|
||||
return filteredPairs.push([name, mockModule]);
|
||||
}
|
||||
|
||||
debug(
|
||||
'WARNING: Cannot find required module `%s` from module `%s`',
|
||||
depNames[i],
|
||||
name,
|
||||
mod.path
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return filteredPairs.push([depNames[i], modDep]);
|
||||
return filteredPairs.push([name, modDep]);
|
||||
});
|
||||
|
||||
response.setResolvedDependencyPairs(mod, filteredPairs);
|
||||
|
||||
Reference in New Issue
Block a user