Skip to content

Commit fc0971c

Browse files
author
Jean Lauliac
committed
jest-haste-map: fix bug where platform-specific files are removed
1 parent 508f789 commit fc0971c

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

packages/jest-haste-map/src/__tests__/index.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ describe('HasteMap', () => {
586586
});
587587
});
588588

589-
it('correctly handles platform-specific file deletions (broken)', async () => {
589+
it('correctly handles platform-specific file deletions', async () => {
590590
mockFs = Object.create(null);
591591
mockFs['/fruits/strawberry.js'] = [
592592
'/**',
@@ -613,8 +613,6 @@ describe('HasteMap', () => {
613613
({__hasteMapForTest: data} = await new HasteMap(defaultConfig).build());
614614
expect(data.map['Strawberry']).toEqual({
615615
g: ['/fruits/strawberry.js', 0],
616-
// FIXME: this file should NOT exist anymore!
617-
ios: ['/fruits/strawberry.ios.js', 0],
618616
});
619617
});
620618

packages/jest-haste-map/src/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,18 @@ class HasteMap extends EventEmitter {
422422
if (fileMetadata[H.VISITED]) {
423423
if (!fileMetadata[H.ID]) {
424424
return null;
425-
} else if (fileMetadata[H.ID] && moduleMetadata) {
426-
map[fileMetadata[H.ID]] = moduleMetadata;
425+
}
426+
if (moduleMetadata != null) {
427+
const platform =
428+
getPlatformExtension(filePath, this._options.platforms) ||
429+
H.GENERIC_PLATFORM;
430+
const module = moduleMetadata[platform];
431+
if (module == null) {
432+
return null;
433+
}
434+
const modulesByPlatform = map[fileMetadata[H.ID]] ||
435+
(map[fileMetadata[H.ID]] = {});
436+
modulesByPlatform[platform] = module;
427437
return null;
428438
}
429439
}

0 commit comments

Comments
 (0)