MCPcopy
hub / github.com/jestjs/jest / setupDuplicates

Function setupDuplicates

packages/jest-haste-map/src/__tests__/index.test.js:1671–1718  ·  view source on GitHub ↗
(hm)

Source from the content-addressed store, hash-verified

1669
1670 describe('recovery from duplicate module IDs', () => {
1671 async function setupDuplicates(hm) {
1672 mockFs[path.join('/', 'project', 'fruits', 'Pear.js')] = `
1673 // Pear!
1674 `;
1675 mockFs[path.join('/', 'project', 'fruits', 'another', 'Pear.js')] = `
1676 // Pear too!
1677 `;
1678 const e = mockEmitters[path.join('/', 'project', 'fruits')];
1679 e.emit(
1680 'all',
1681 'change',
1682 'Pear.js',
1683 path.join('/', 'project', 'fruits'),
1684 MOCK_STAT_FILE,
1685 );
1686 e.emit(
1687 'all',
1688 'add',
1689 'Pear.js',
1690 path.join('/', 'project', 'fruits', 'another'),
1691 MOCK_STAT_FILE,
1692 );
1693 const {hasteFS, moduleMap} = await waitForItToChange(hm);
1694 expect(
1695 hasteFS.exists(
1696 path.join('/', 'project', 'fruits', 'another', 'Pear.js'),
1697 ),
1698 ).toBe(true);
1699 try {
1700 moduleMap.getModule('Pear');
1701 throw new Error('should be unreachable');
1702 } catch (error) {
1703 const {DuplicateHasteCandidatesError} =
1704 require('../ModuleMap').default;
1705 expect(error).toBeInstanceOf(DuplicateHasteCandidatesError);
1706 expect(error.hasteName).toBe('Pear');
1707 expect(error.platform).toBe('g');
1708 expect(error.supportsNativePlatform).toBe(false);
1709 expect(error.duplicatesSet).toEqual(
1710 createMap({
1711 [path.join('/', 'project', 'fruits', 'Pear.js')]: H.MODULE,
1712 [path.join('/', 'project', 'fruits', 'another', 'Pear.js')]:
1713 H.MODULE,
1714 }),
1715 );
1716 expect(error.message.replaceAll('\\', '/')).toMatchSnapshot();
1717 }
1718 }
1719
1720 hm_it(
1721 'recovers when the oldest version of the duplicates is fixed',

Callers 1

index.test.jsFile · 0.85

Calls 10

waitForItToChangeFunction · 0.85
expectFunction · 0.85
toBeMethod · 0.80
toBeInstanceOfMethod · 0.80
toEqualMethod · 0.80
toMatchSnapshotMethod · 0.80
createMapFunction · 0.70
existsMethod · 0.65
getModuleMethod · 0.65
emitMethod · 0.45

Tested by

no test coverage detected