xplat/js/metro: DependencyGraph: reject on duplicate modules

Reviewed By: davidaurelio

Differential Revision: D7398617

fbshipit-source-id: eaac785d94b827502c2c50d8ec53ae251547a8a5
This commit is contained in:
Jean Lauliac 2018-04-03 09:24:27 -07:00 committed by Facebook Github Bot
parent 01599ed55e
commit 72a66fa8e4
2 changed files with 14 additions and 19 deletions

View File

@ -969,7 +969,7 @@ describe('traverseDependencies', function() {
});
});
it('should fatal on multiple modules with the same name (actually broken)', async () => {
it('should fatal on multiple modules with the same name', async () => {
const root = '/root';
console.warn = jest.fn();
setMockFileSystem({
@ -981,24 +981,18 @@ describe('traverseDependencies', function() {
const opts = {...defaults, projectRoots: [root]};
// FIXME: This is broken, jest-haste-map does not fatal on modules with
// the same name, because not fataling was required for supporting some
// OSS projects. We'd like to enable it someday.
//try {
try {
await processDgraph(opts, async dgraph => {});
// throw new Error('should be unreachable');
// } catch (error) {
// expect(error.message).toEqual(
// `Failed to build DependencyGraph: @providesModule naming collision:\n` +
// ` Duplicate module name: index\n` +
// ` Paths: /root/b.js collides with /root/index.js\n\n` +
// 'This error is caused by a @providesModule declaration ' +
// 'with the same name across two different files.',
// );
// expect(error.type).toEqual('DependencyGraphError');
// expect(console.warn).toBeCalled();
// }
throw new Error('should be unreachable');
} catch (error) {
expect(error.message).toEqual(
`jest-haste-map: @providesModule naming collision:\n` +
` Duplicate module name: index\n` +
` Paths: /root/b.js collides with /root/index.js\n\n` +
'This error is caused by a @providesModule declaration ' +
'with the same name across two different files.',
);
}
});
it('throws when a module is missing', async () => {

View File

@ -119,6 +119,7 @@ class DependencyGraph extends EventEmitter {
resetCache: opts.resetCache,
retainAllFiles: true,
roots: opts.projectRoots,
throwOnModuleCollision: true,
useWatchman,
watch: opts.watch,
});