mirror of https://github.com/status-im/metro.git
Limit mocks shared with a resolution response
Reviewed By: davidaurelio Differential Revision: D2872340 fb-gh-sync-id: a76b580ff670115cd4bd0098e7b9f31110239369
This commit is contained in:
parent
1f2e16c0af
commit
1de20b0135
|
@ -104,10 +104,9 @@ class ResolutionRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrderedDependencies(response, mocksPattern) {
|
getOrderedDependencies(response, mocksPattern) {
|
||||||
return this._getAllMocks(mocksPattern).then(mocks => {
|
return this._getAllMocks(mocksPattern).then(allMocks => {
|
||||||
response.setMocks(mocks);
|
|
||||||
|
|
||||||
const entry = this._moduleCache.getModule(this._entryPath);
|
const entry = this._moduleCache.getModule(this._entryPath);
|
||||||
|
const mocks = Object.create(null);
|
||||||
const visited = Object.create(null);
|
const visited = Object.create(null);
|
||||||
visited[entry.hash()] = true;
|
visited[entry.hash()] = true;
|
||||||
|
|
||||||
|
@ -118,13 +117,14 @@ class ResolutionRequest {
|
||||||
depNames.map(name => this.resolveDependency(mod, name))
|
depNames.map(name => this.resolveDependency(mod, name))
|
||||||
).then((dependencies) => [depNames, dependencies])
|
).then((dependencies) => [depNames, dependencies])
|
||||||
).then(([depNames, dependencies]) => {
|
).then(([depNames, dependencies]) => {
|
||||||
if (mocks) {
|
if (allMocks) {
|
||||||
return mod.getName().then(name => {
|
return mod.getName().then(name => {
|
||||||
if (mocks[name]) {
|
if (allMocks[name]) {
|
||||||
const mockModule =
|
const mockModule =
|
||||||
this._moduleCache.getModule(mocks[name]);
|
this._moduleCache.getModule(allMocks[name]);
|
||||||
depNames.push(name);
|
depNames.push(name);
|
||||||
dependencies.push(mockModule);
|
dependencies.push(mockModule);
|
||||||
|
mocks[name] = allMocks[name];
|
||||||
}
|
}
|
||||||
return [depNames, dependencies];
|
return [depNames, dependencies];
|
||||||
});
|
});
|
||||||
|
@ -141,8 +141,9 @@ 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 (mocks && mocks[name]) {
|
if (allMocks && allMocks[name]) {
|
||||||
const mockModule = this._moduleCache.getModule(mocks[name]);
|
const mockModule = this._moduleCache.getModule(allMocks[name]);
|
||||||
|
mocks[name] = allMocks[name];
|
||||||
return filteredPairs.push([name, mockModule]);
|
return filteredPairs.push([name, mockModule]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +173,7 @@ class ResolutionRequest {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return collect(entry);
|
return collect(entry).then(() => response.setMocks(mocks));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4117,11 +4117,11 @@ describe('DependencyGraph', function() {
|
||||||
return dgraph.getDependencies('/root/index.js')
|
return dgraph.getDependencies('/root/index.js')
|
||||||
.then(response => response.finalize())
|
.then(response => response.finalize())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
expect(response.mocks).toBe(null);
|
expect(response.mocks).toEqual({});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('retrieves a list of all mocks in the system', () => {
|
pit('retrieves a list of all required mocks', () => {
|
||||||
var root = '/root';
|
var root = '/root';
|
||||||
fs.__setMockFilesystem({
|
fs.__setMockFilesystem({
|
||||||
'root': {
|
'root': {
|
||||||
|
@ -4133,6 +4133,7 @@ describe('DependencyGraph', function() {
|
||||||
'/**',
|
'/**',
|
||||||
' * @providesModule b',
|
' * @providesModule b',
|
||||||
' */',
|
' */',
|
||||||
|
'require("A");',
|
||||||
].join('\n'),
|
].join('\n'),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue