Limit mocks shared with a resolution response

Reviewed By: davidaurelio

Differential Revision: D2872340

fb-gh-sync-id: a76b580ff670115cd4bd0098e7b9f31110239369
This commit is contained in:
Christoph Pojer 2016-01-27 18:46:23 -08:00 committed by facebook-github-bot-7
parent 1f2e16c0af
commit 1de20b0135
2 changed files with 13 additions and 11 deletions

View File

@ -104,10 +104,9 @@ class ResolutionRequest {
}
getOrderedDependencies(response, mocksPattern) {
return this._getAllMocks(mocksPattern).then(mocks => {
response.setMocks(mocks);
return this._getAllMocks(mocksPattern).then(allMocks => {
const entry = this._moduleCache.getModule(this._entryPath);
const mocks = Object.create(null);
const visited = Object.create(null);
visited[entry.hash()] = true;
@ -118,13 +117,14 @@ class ResolutionRequest {
depNames.map(name => this.resolveDependency(mod, name))
).then((dependencies) => [depNames, dependencies])
).then(([depNames, dependencies]) => {
if (mocks) {
if (allMocks) {
return mod.getName().then(name => {
if (mocks[name]) {
if (allMocks[name]) {
const mockModule =
this._moduleCache.getModule(mocks[name]);
this._moduleCache.getModule(allMocks[name]);
depNames.push(name);
dependencies.push(mockModule);
mocks[name] = allMocks[name];
}
return [depNames, dependencies];
});
@ -141,8 +141,9 @@ class ResolutionRequest {
// 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]);
if (allMocks && allMocks[name]) {
const mockModule = this._moduleCache.getModule(allMocks[name]);
mocks[name] = allMocks[name];
return filteredPairs.push([name, mockModule]);
}
@ -172,7 +173,7 @@ class ResolutionRequest {
});
};
return collect(entry);
return collect(entry).then(() => response.setMocks(mocks));
});
}

View File

@ -4117,11 +4117,11 @@ describe('DependencyGraph', function() {
return dgraph.getDependencies('/root/index.js')
.then(response => response.finalize())
.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';
fs.__setMockFilesystem({
'root': {
@ -4133,6 +4133,7 @@ describe('DependencyGraph', function() {
'/**',
' * @providesModule b',
' */',
'require("A");',
].join('\n'),
},
});