From 9294f5a46aff3c8314986ab7e23d3a010f1fbdff Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 14 Sep 2017 08:16:12 -0700 Subject: [PATCH] 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 --- .../src/DeltaBundler/DeltaCalculator.js | 8 ++++++++ .../__tests__/DeltaCalculator-test.js | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js b/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js index af8591b3..68bb4e6f 100644 --- a/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js +++ b/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js @@ -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; } diff --git a/packages/metro-bundler/src/DeltaBundler/__tests__/DeltaCalculator-test.js b/packages/metro-bundler/src/DeltaBundler/__tests__/DeltaCalculator-test.js index 83b12a5d..17fd4965 100644 --- a/packages/metro-bundler/src/DeltaBundler/__tests__/DeltaCalculator-test.js +++ b/packages/metro-bundler/src/DeltaBundler/__tests__/DeltaCalculator-test.js @@ -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); + }); });