Skip to content

Commit

Permalink
packager: DependencyGraph-test: add broken use case
Browse files Browse the repository at this point in the history
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, jestjs/jest#3107

Reviewed By: davidaurelio

Differential Revision: D4673431

fbshipit-source-id: 05e09bdf61a2eddf2e9d1e32a33d32065c9051f1
  • Loading branch information
Jean Lauliac authored and facebook-github-bot committed Mar 16, 2017
1 parent 3bb9512 commit a1694ba
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions packager/src/node-haste/__tests__/DependencyGraph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit a1694ba

Please sign in to comment.