From a1694ba86b03a06979c6c5623332341fc354aceb Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Thu, 16 Mar 2017 13:49:51 -0700 Subject: [PATCH] packager: DependencyGraph-test: add broken use case Summary: This changeset adds a test that verifies that the duplicate modules use case is broken. The goal is to acknowledge the problem for now, and when we update `jest-haste`, we'll simply fix what needs to be fixed in that test. See also, https://github.com/facebook/jest/pull/3107 Reviewed By: davidaurelio Differential Revision: D4673431 fbshipit-source-id: 05e09bdf61a2eddf2e9d1e32a33d32065c9051f1 --- .../__tests__/DependencyGraph-test.js | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/packager/src/node-haste/__tests__/DependencyGraph-test.js b/packager/src/node-haste/__tests__/DependencyGraph-test.js index 4a60d0b55..f55ee0a91 100644 --- a/packager/src/node-haste/__tests__/DependencyGraph-test.js +++ b/packager/src/node-haste/__tests__/DependencyGraph-test.js @@ -5181,6 +5181,69 @@ describe('DependencyGraph', function() { expect(deps).toBeDefined(); }); }); + + it('should recover from multiple modules with the same name (but this is broken right now)', async () => { + const root = '/root'; + console.warn = jest.fn(); + const filesystem = setMockFileSystem({ + 'root': { + 'index.js': [ + '/**', + ' * @providesModule index', + ' */', + 'require(\'a\')', + 'require(\'b\')', + ].join('\n'), + 'a.js': [ + '/**', + ' * @providesModule a', + ' */', + ].join('\n'), + 'b.js': [ + '/**', + ' * @providesModule b', + ' */', + ].join('\n'), + }, + }); + + const dgraph = DependencyGraph.load({...defaults, roots: [root]}); + await getOrderedDependenciesAsJSON(dgraph, root + '/index.js'); + filesystem.root['b.js'] = [ + '/**', + ' * @providesModule a', + ' */', + ].join('\n'); + await triggerAndProcessWatchEvent(dgraph, 'change', root + '/b.js'); + try { + await getOrderedDependenciesAsJSON(dgraph, root + '/index.js'); + throw new Error('expected `getOrderedDependenciesAsJSON` to fail'); + } catch (error) { + if (error.type !== 'UnableToResolveError') { + throw error; + } + expect(console.warn).toBeCalled(); + filesystem.root['b.js'] = [ + '/**', + ' * @providesModule b', + ' */', + ].join('\n'); + await triggerAndProcessWatchEvent(dgraph, 'change', root + '/b.js'); + } + + // This verifies that it is broken right now. Instead of throwing it should + // return correct results. Once this is fixed in `jest-haste`, remove + // the whole try catch and verify results are matching a snapshot. + try { + await getOrderedDependenciesAsJSON(dgraph, root + '/index.js'); + throw new Error('expected `getOrderedDependenciesAsJSON` to fail'); + } catch (error) { + if (error.type !== 'UnableToResolveError') { + throw error; + } + } + }); + }); describe('Extensions', () => {