Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
robhogan committed Dec 9, 2024
1 parent 4a216e5 commit 7d9ca1f
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions packages/metro-file-map/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,61 @@ describe('FileMap', () => {
}
}

fm_it(
'does not throw on a duplicate created at runtime even if throwOnModuleCollision: true',
async hm => {
mockFs[path.join('/', 'project', 'fruits', 'Pear.js')] = `
// Pear!
`;
mockFs[path.join('/', 'project', 'fruits', 'another', 'Pear.js')] = `
// Pear too!
`;
const {fileSystem} = await hm.build();
const e = mockEmitters[path.join('/', 'project', 'fruits')];
e.emit(
'all',
'change',
'Pear.js',
path.join('/', 'project', 'fruits'),
MOCK_CHANGE_FILE,
);
e.emit(
'all',
'add',
'Pear.js',
path.join('/', 'project', 'fruits', 'another'),
MOCK_CHANGE_FILE,
);
await new Promise((resolve, reject) => {
console.error.mockImplementationOnce(() => {
reject(new Error('should not print error'));
});
hm.once('change', resolve);
});
// Expect a warning to be printed, but no error.
expect(console.warn).toHaveBeenCalledWith(
expect.stringContaining(
'metro-file-map: Haste module naming collision: Pear',
),
);
// Both files should be added to the fileSystem, despite the Haste
// collision
expect(
fileSystem.exists(path.join('/', 'project', 'fruits', 'Pear.js')),
).toBe(true);
expect(
fileSystem.exists(
path.join('/', 'project', 'fruits', 'another', 'Pear.js'),
),
).toBe(true);
},
{
config: {
throwOnModuleCollision: true,
},
},
);

fm_it(
'recovers when the oldest version of the duplicates is fixed',
async hm => {
Expand Down

0 comments on commit 7d9ca1f

Please sign in to comment.