Do not do unnecessary work when re-adding a file after deleting it

Reviewed By: mjesun

Differential Revision: D7009760

fbshipit-source-id: 18a93443226bdec4decb69f75539e27f528c128c
This commit is contained in:
Rafael Oleza 2018-02-19 06:41:48 -08:00 committed by Facebook Github Bot
parent a5307e986e
commit cfe175254a
3 changed files with 25 additions and 22 deletions

View File

@ -220,6 +220,7 @@ class DeltaCalculator extends EventEmitter {
this._deletedFiles.add(filePath); this._deletedFiles.add(filePath);
this._modifiedFiles.delete(filePath); this._modifiedFiles.delete(filePath);
} else { } else {
this._deletedFiles.delete(filePath);
this._modifiedFiles.add(filePath); this._modifiedFiles.add(filePath);
} }

View File

@ -313,6 +313,30 @@ describe('DeltaCalculator', () => {
expect(traverseDependencies.mock.calls[0][0]).toEqual(['/bundle']); expect(traverseDependencies.mock.calls[0][0]).toEqual(['/bundle']);
}); });
it('should not do unnecessary work when adding a file after deleting it', async () => {
await deltaCalculator.getDelta();
// First delete a file
fileWatcher.emit('change', {
eventsQueue: [{type: 'delete', filePath: '/foo'}],
});
// Then add it again
fileWatcher.emit('change', {eventsQueue: [{filePath: '/foo'}]});
traverseDependencies.mockReturnValue(
Promise.resolve({
added: new Map([['/foo', edgeModule]]),
deleted: new Set(),
}),
);
await deltaCalculator.getDelta();
expect(traverseDependencies).toHaveBeenCalledTimes(1);
expect(traverseDependencies.mock.calls[0][0]).toEqual(['/foo']);
});
describe('getTransformerOptions()', () => { describe('getTransformerOptions()', () => {
it('should calculate the transform options correctly', async () => { it('should calculate the transform options correctly', async () => {
expect(await deltaCalculator.getTransformerOptions()).toEqual({ expect(await deltaCalculator.getTransformerOptions()).toEqual({

View File

@ -221,28 +221,6 @@ describe('edge cases', () => {
}); });
}); });
it('modify a file and delete it afterwards', async () => {
const edges = new Map();
await initialTraverseDependencies('/bundle', dependencyGraph, {}, edges);
mockedDependencyTree.set(moduleFoo.path, [moduleBar]);
// Modify /baz, rename it to /qux and modify it again.
expect(
getPaths(
await traverseDependencies(
['/baz', '/foo'],
dependencyGraph,
{},
edges,
),
),
).toEqual({
added: new Set(['/foo']),
deleted: new Set(['/baz']),
});
});
it('move a file to a different folder', async () => { it('move a file to a different folder', async () => {
const edges = new Map(); const edges = new Map();
await initialTraverseDependencies('/bundle', dependencyGraph, {}, edges); await initialTraverseDependencies('/bundle', dependencyGraph, {}, edges);