Multiple requests to the Delta Bundler when there is an error should produce an Error

Reviewed By: jeanlauliac

Differential Revision: D5814215

fbshipit-source-id: 9a72057078819d07ddbd5d4f949d7bdf13aff29e
This commit is contained in:
Rafael Oleza 2017-09-14 08:16:12 -07:00 committed by Facebook Github Bot
parent 3401cfe768
commit 9294f5a46a
2 changed files with 23 additions and 0 deletions

View File

@ -103,6 +103,14 @@ class DeltaCalculator extends EventEmitter {
try {
result = await this._currentBuildPromise;
} catch (error) {
// In case of error, we don't want to mark the modified files as
// processed (since we haven't actually created any delta). If we do not
// do so, asking for a delta after an error will produce an empty Delta,
// which is not correct.
modifiedFiles.forEach(file => this._modifiedFiles.add(file));
throw error;
} finally {
this._currentBuildPromise = null;
}

View File

@ -234,4 +234,19 @@ describe('DeltaCalculator', () => {
expect(onChangeFile.mock.calls.length).toBe(0);
});
it('should retry to build the last delta after getting an error', async () => {
await deltaCalculator.getDelta();
fileWatcher.emit('change', {eventsQueue: [{filePath: '/foo'}]});
Bundler.prototype.getShallowDependencies.mockImplementation(async () => {
throw new Error('error');
});
await expect(deltaCalculator.getDelta()).rejects.toBeInstanceOf(Error);
// This second time it should still throw an error.
await expect(deltaCalculator.getDelta()).rejects.toBeInstanceOf(Error);
});
});